svn commit: r430281 - /incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r430281 - /incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java

jacopoc
Author: jacopoc
Date: Wed Aug  9 23:29:27 2006
New Revision: 430281

URL: http://svn.apache.org/viewvc?rev=430281&view=rev
Log:
Added support for select box rendering in fo widget forms: the selected value is shown.

Modified:
    incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java

Modified: incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java?rev=430281&r1=430280&r2=430281&view=diff
==============================================================================
--- incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java (original)
+++ incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/fo/FoFormRenderer.java Wed Aug  9 23:29:27 2006
@@ -132,7 +132,28 @@
     public void renderDropDownField(StringBuffer buffer, Map context, DropDownField dropDownField) {
         ModelFormField modelFormField = dropDownField.getModelFormField();
         ModelForm modelForm = modelFormField.getModelForm();
-        this.makeBlockString(buffer, modelFormField.getWidgetStyle(), modelFormField.getEntry(context));
+        String currentValue = modelFormField.getEntry(context);
+        List allOptionValues = dropDownField.getAllOptionValues(context, modelForm.getDelegator());
+        // if the current value should go first, display it
+        if (UtilValidate.isNotEmpty(currentValue) && "first-in-list".equals(dropDownField.getCurrent())) {
+            String explicitDescription = dropDownField.getCurrentDescription(context);
+            if (UtilValidate.isNotEmpty(explicitDescription)) {
+                this.makeBlockString(buffer, modelFormField.getWidgetStyle(), explicitDescription);
+            } else {
+                this.makeBlockString(buffer, modelFormField.getWidgetStyle(), ModelFormField.FieldInfoWithOptions.getDescriptionForOptionKey(currentValue, allOptionValues));
+            }
+        } else {
+            Iterator optionValueIter = allOptionValues.iterator();
+            while (optionValueIter.hasNext()) {
+                ModelFormField.OptionValue optionValue = (ModelFormField.OptionValue) optionValueIter.next();
+                String noCurrentSelectedKey = dropDownField.getNoCurrentSelectedKey(context);
+                if ((UtilValidate.isNotEmpty(currentValue) && currentValue.equals(optionValue.getKey()) && "selected".equals(dropDownField.getCurrent())) ||
+                        (UtilValidate.isEmpty(currentValue) && noCurrentSelectedKey != null && noCurrentSelectedKey.equals(optionValue.getKey()))) {
+                    this.makeBlockString(buffer, modelFormField.getWidgetStyle(), optionValue.getDescription());
+                    break;
+                }
+            }
+        }
         this.appendWhitespace(buffer);
     }