diff --git a/framework/widget/dtd/widget-form.xsd b/framework/widget/dtd/widget-form.xsd index 3d87b6950f..3af2967766 100644 --- a/framework/widget/dtd/widget-form.xsd +++ b/framework/widget/dtd/widget-form.xsd @@ -299,6 +299,7 @@ under the License. + @@ -362,6 +363,14 @@ under the License. + + + last-field reorder the given field at the end form. This element is propagated to the inherited form + + + + + diff --git a/framework/widget/src/org/ofbiz/widget/form/ModelForm.java b/framework/widget/src/org/ofbiz/widget/form/ModelForm.java index 76e2a1203c..ba8d37603e 100644 --- a/framework/widget/src/org/ofbiz/widget/form/ModelForm.java +++ b/framework/widget/src/org/ofbiz/widget/form/ModelForm.java @@ -133,6 +133,7 @@ public class ModelForm extends ModelWidget { protected List altTargets = FastList.newInstance(); protected List autoFieldsServices = FastList.newInstance(); protected List autoFieldsEntities = FastList.newInstance(); + protected List lastOrderFields = FastList.newInstance(); protected List sortOrderFields = FastList.newInstance(); protected List altRowStyles = FastList.newInstance(); @@ -320,6 +321,7 @@ public class ModelForm extends ModelWidget { this.fieldGroupMap = parent.fieldGroupMap; this.fieldGroupList = parent.fieldGroupList; + this.lastOrderFields = parent.lastOrderFields; } } @@ -543,6 +545,10 @@ public class ModelForm extends ModelWidget { String position = sortFieldElement.getAttribute("position"); this.sortOrderFields.add(new SortField(fieldName, position)); this.fieldGroupMap.put(fieldName, lastFieldGroup); + } else if (tagName.equals("last-field")) { + String fieldName = sortFieldElement.getAttribute("name"); + this.fieldGroupMap.put(fieldName, lastFieldGroup); + this.lastOrderFields.add(fieldName); } else if (tagName.equals("banner")) { Banner thisBanner = new Banner(sortFieldElement, this); this.fieldGroupList.add(thisBanner); @@ -588,6 +594,27 @@ public class ModelForm extends ModelWidget { this.fieldList = sortedFields; } + if (UtilValidate.isNotEmpty(this.lastOrderFields)) { + List lastedFields = FastList.newInstance(); + for (String fieldName: this.lastOrderFields) { + if (UtilValidate.isEmpty(fieldName)) { + continue; + } + // get all fields with the given name from the existing list and put them in the lasted list + Iterator fieldIter = this.fieldList.iterator(); + while (fieldIter.hasNext()) { + ModelFormField modelFormField = fieldIter.next(); + if (fieldName.equals(modelFormField.getName())) { + // matched the name; remove from the original last and add to the lasted list + fieldIter.remove(); + lastedFields.add(modelFormField); + } + } + } + //now put all lastedFields at the field list end + this.fieldList.addAll(lastedFields); + } + // read all actions under the "actions" element Element actionsElement = UtilXml.firstChildElement(formElement, "actions"); if (actionsElement != null) {