svn commit: r773120 - in /ofbiz/branches/release09.04: ./ framework/widget/dtd/widget-form.xsd framework/widget/src/org/ofbiz/widget/form/ModelForm.java

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

svn commit: r773120 - in /ofbiz/branches/release09.04: ./ framework/widget/dtd/widget-form.xsd framework/widget/src/org/ofbiz/widget/form/ModelForm.java

jleroux@apache.org
Author: jleroux
Date: Fri May  8 22:03:35 2009
New Revision: 773120

URL: http://svn.apache.org/viewvc?rev=773120&view=rev
Log:
"Applied fix from trunk for revision: 772464"
------------------------------------------------------------------------
r772464 | lektran | 2009-05-07 01:26:00 +0200 (jeu., 07 mai 2009) | 1 line

Fix the problem of fields without a use-when not overriding fields with a use-when condition OFBIZ-863
------------------------------------------------------------------------


Modified:
    ofbiz/branches/release09.04/   (props changed)
    ofbiz/branches/release09.04/framework/widget/dtd/widget-form.xsd
    ofbiz/branches/release09.04/framework/widget/src/org/ofbiz/widget/form/ModelForm.java

Propchange: ofbiz/branches/release09.04/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri May  8 22:03:35 2009
@@ -1 +1 @@
-/ofbiz/trunk:765933,766011,766015,766293,766307,766316,766325,766462,766522,766800,767060,767072,767093,767098-767099,767102,767123,767125,767127,767279,767287,767671,767688,767694,767822,767845,768358,768490,768550,768675,768686,768705,768811,768815,768960,769030,769500,770272,770997,771073,772401,772465,773076
+/ofbiz/trunk:765933,766011,766015,766293,766307,766316,766325,766462,766522,766800,767060,767072,767093,767098-767099,767102,767123,767125,767127,767279,767287,767671,767688,767694,767822,767845,768358,768490,768550,768675,768686,768705,768811,768815,768960,769030,769500,770272,770997,771073,772401,772464-772465,773076

Modified: ofbiz/branches/release09.04/framework/widget/dtd/widget-form.xsd
URL: http://svn.apache.org/viewvc/ofbiz/branches/release09.04/framework/widget/dtd/widget-form.xsd?rev=773120&r1=773119&r2=773120&view=diff
==============================================================================
--- ofbiz/branches/release09.04/framework/widget/dtd/widget-form.xsd (original)
+++ ofbiz/branches/release09.04/framework/widget/dtd/widget-form.xsd Fri May  8 22:03:35 2009
@@ -455,7 +455,11 @@
             </xs:simpleType>
         </xs:attribute>
         <xs:attribute name="use-when" type="xs:string">
-            <xs:annotation><xs:documentation>Used to specify a condition that must be true to use this field; the condition should be written using the Java syntax and can operate on values in the form context; if this is used the field will only be put on the field list, and not in the field map meaning that values for this field cannot be overridden.</xs:documentation></xs:annotation>
+            <xs:annotation><xs:documentation>
+                Used to specify a condition that must be true to use this field; the condition should be written using the
+                Java syntax and can operate on values in the form context; conditional fields are evaluated in reverse
+                order so the last field defined that evaluates to true is the one that is rendered.
+            </xs:documentation></xs:annotation>
         </xs:attribute>
         <xs:attribute name="encode-output" default="true">
             <xs:annotation><xs:documentation>

Modified: ofbiz/branches/release09.04/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release09.04/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=773120&r1=773119&r2=773120&view=diff
==============================================================================
--- ofbiz/branches/release09.04/framework/widget/src/org/ofbiz/widget/form/ModelForm.java (original)
+++ ofbiz/branches/release09.04/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Fri May  8 22:03:35 2009
@@ -145,11 +145,13 @@
      */
     protected List<ModelFormField> fieldList = FastList.newInstance();
 
-    /** This Map is keyed with the field name and has a ModelFormField for the value; fields
-     * with conditions will not be put in this Map so field definition overrides for fields
-     * with conditions is not possible.
+    /** This Map is keyed with the field name and has a ModelFormField for the value.
      */
     protected Map<String, ModelFormField> fieldMap = FastMap.newInstance();
+    
+    /** Keeps track of conditional fields to help ensure that only one is rendered
+     */
+    protected Set<String> useWhenFields = FastSet.newInstance();
 
     /** This is a list of FieldGroups in the order they were created.
      * Can also include Banner objects.
@@ -293,6 +295,8 @@
                 this.onSubmitUpdateAreas = parent.onSubmitUpdateAreas;
                 this.onPaginateUpdateAreas = parent.onPaginateUpdateAreas;
                 this.altRowStyles = parent.altRowStyles;
+                
+                this.useWhenFields = parent.useWhenFields;
 
                 //these are done below in a special way...
                 //this.fieldList = parent.fieldList;
@@ -596,12 +600,13 @@
      * @return The same ModelFormField, or if merged with an existing field, the existing field.
      */
     public ModelFormField addUpdateField(ModelFormField modelFormField) {
-        if (!modelFormField.isUseWhenEmpty()) {
+        if (!modelFormField.isUseWhenEmpty() || useWhenFields.contains(modelFormField.getName())) {
+            useWhenFields.add(modelFormField.getName());
             // is a conditional field, add to the List but don't worry about the Map
             //for adding to list, see if there is another field with that name in the list and if so, put it before that one
             boolean inserted = false;
             for (int i = 0; i < this.fieldList.size(); i++) {
-                ModelFormField curField = (ModelFormField) this.fieldList.get(i);
+                ModelFormField curField = this.fieldList.get(i);
                 if (curField.getName() != null && curField.getName().equals(modelFormField.getName())) {
                     this.fieldList.add(i, modelFormField);
                     inserted = true;
@@ -615,7 +620,7 @@
         } else {
 
             // not a conditional field, see if a named field exists in Map
-            ModelFormField existingField = (ModelFormField) this.fieldMap.get(modelFormField.getName());
+            ModelFormField existingField = this.fieldMap.get(modelFormField.getName());
             if (existingField != null) {
                 // does exist, update the field by doing a merge/override
                 existingField.mergeOverrideModelFormField(modelFormField);
@@ -848,7 +853,7 @@
         // Check to see if there is a field, same name and same use-when (could come from extended form)
         for (int j = 0; j < tempFieldList.size(); j++) {
             ModelFormField modelFormField = (ModelFormField) tempFieldList.get(j);
-            if (!modelFormField.isUseWhenEmpty()) {
+            if (this.useWhenFields.contains(modelFormField.getName())) {
                 boolean shouldUse1 = modelFormField.shouldUse(context);
                 for (int i = j+1; i < tempFieldList.size(); i++) {
                     ModelFormField curField = (ModelFormField) tempFieldList.get(i);