You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by le...@apache.org on 2009/05/07 01:26:00 UTC
svn commit: r772464 - in /ofbiz/trunk/framework/widget: dtd/widget-form.xsd
src/org/ofbiz/widget/form/ModelForm.java
Author: lektran
Date: Wed May 6 23:26:00 2009
New Revision: 772464
URL: http://svn.apache.org/viewvc?rev=772464&view=rev
Log:
Fix the problem of fields without a use-when not overriding fields with a use-when condition OFBIZ-863
Modified:
ofbiz/trunk/framework/widget/dtd/widget-form.xsd
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
Modified: ofbiz/trunk/framework/widget/dtd/widget-form.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-form.xsd?rev=772464&r1=772463&r2=772464&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original)
+++ ofbiz/trunk/framework/widget/dtd/widget-form.xsd Wed May 6 23:26:00 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/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=772464&r1=772463&r2=772464&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Wed May 6 23:26:00 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);