From bf2feb63bd17e9ae2028f4e12775a05e3270a2ce Mon Sep 17 00:00:00 2001 From: Jacques Le Roux Date: Sat, 31 Mar 2012 12:10:07 +0000 Subject: [PATCH] A patch from Nicolas Malin "add possibility to sort field at the end form on widget form" https://issues.apache.org/jira/browse/OFBIZ-4518 When you use sort-field, you reorder only the form begin or you need list all file if you want reordered the end form. Example
If you want put c at the end :
with the patch
It's really useful for inherited forms when you adding new fields, you just use last-field for instance for submit button. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1307784 13f79535-47bb-0310-9956-ffa450edef68 --- framework/widget/dtd/widget-form.xsd | 9 +++++++ .../src/org/ofbiz/widget/form/ModelForm.java | 27 +++++++++++++++++++ 2 files changed, 36 insertions(+) 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) {