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

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@772464 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Scott Gray
2009-05-06 23:26:00 +00:00
parent 6200ce377a
commit cd6bbff043
2 changed files with 17 additions and 8 deletions
+5 -1
View File
@@ -455,7 +455,11 @@ under the License.
</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>
@@ -145,11 +145,13 @@ public class ModelForm extends ModelWidget {
*/
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 @@ public class ModelForm extends ModelWidget {
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 @@ public class ModelForm extends ModelWidget {
* @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 @@ public class ModelForm extends ModelWidget {
} 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 @@ public class ModelForm extends ModelWidget {
// 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);