You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ap...@apache.org on 2009/07/18 07:27:58 UTC

svn commit: r795315 - /ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java

Author: apatel
Date: Sat Jul 18 05:27:54 2009
New Revision: 795315

URL: http://svn.apache.org/viewvc?rev=795315&view=rev
Log:
Enhancement to dropdown element of form widget. Now it can handle data of types other then String.

Modified:
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java?rev=795315&r1=795314&r2=795315&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java Sat Jul 18 05:27:54 2009
@@ -1611,7 +1611,7 @@
     public static class ListOptions extends OptionSource {
         protected FlexibleMapAccessor<List<? extends Object>> listAcsr;
         protected String listEntryName;
-        protected FlexibleMapAccessor<String> keyAcsr;
+        protected FlexibleMapAccessor<Object> keyAcsr;
         protected FlexibleStringExpander description;
 
         public ListOptions(String listName, String listEntryName, String keyName, String description, FieldInfo fieldInfo) {
@@ -1644,7 +1644,19 @@
                         Map<String, Object> dataMap = UtilGenerics.checkMap(data);
                         localContext.putAll(dataMap);
                     }
-                    optionValues.add(new OptionValue((String) keyAcsr.get(localContext), description.expandString(localContext)));
+                    Object keyObj = keyAcsr.get(localContext);
+                    String key = null;
+                    if (keyObj instanceof String) {
+                        key = (String) keyObj;
+                    } else {
+                        try {
+                            key = (String) ObjectType.simpleTypeConvert(keyObj, "String", null, null);
+                        } catch (GeneralException e) {
+                            String errMsg = "Could not convert field value for the field: [" + this.keyAcsr.toString() + "] to String for the value [" + keyObj + "]: " + e.toString();
+                            Debug.logError(e, errMsg, module);
+                        }
+                    }
+                    optionValues.add(new OptionValue(key, description.expandString(localContext)));
                 }
             }
         }