Author: jleroux
Date: Sat Mar 31 12:10:07 2012 New Revision: 1307784 URL: http://svn.apache.org/viewvc?rev=1307784&view=rev Log: 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 <form> <field name="a"/> <field name="b"/> <field name="c"/> <field name="d"/> </form> If you want put c at the end : <form> <field name="a"/> <field name="b"/> <field name="c"/> <field name="d"/> <sort-order> <sort-field name="a"/> <sort-field name="b"/> <sort-field name="d"/> <sort-field name="c"/> </sort-order> </form> with the patch <form> <field name="a"/> <field name="b"/> <field name="c"/> <field name="d"/> <sort-order> <last-field name="c"/> </sort-order> </form> It's really useful for inherited forms when you adding new fields, you just use last-field for instance for submit button. 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=1307784&r1=1307783&r2=1307784&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original) +++ ofbiz/trunk/framework/widget/dtd/widget-form.xsd Sat Mar 31 12:10:07 2012 @@ -299,6 +299,7 @@ under the License. <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element ref="sort-field"/> + <xs:element ref="last-field"/> <xs:element ref="field-group"/> <xs:element ref="banner"/> </xs:choice> @@ -362,6 +363,14 @@ under the License. <xs:attributeGroup name="attlist.sort-field"> <xs:attribute name="name" type="xs:string" use="required"/> </xs:attributeGroup> + <xs:element name="last-field"> + <xs:annotation> + <xs:documentation>last-field reorder the given field at the end form. This element is propagated to the inherited form</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:attributeGroup ref="attlist.sort-field"/> + </xs:complexType> + </xs:element> <!-- ================== Form Events ==================== --> <xs:attributeGroup name="attlist.on-form-event-update-area"> <xs:attribute name="event-type" use="required"> 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=1307784&r1=1307783&r2=1307784&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 Sat Mar 31 12:10:07 2012 @@ -133,6 +133,7 @@ public class ModelForm extends ModelWidg protected List<AltTarget> altTargets = FastList.newInstance(); protected List<AutoFieldsService> autoFieldsServices = FastList.newInstance(); protected List<AutoFieldsEntity> autoFieldsEntities = FastList.newInstance(); + protected List<String> lastOrderFields = FastList.newInstance(); protected List<SortField> sortOrderFields = FastList.newInstance(); protected List<AltRowStyle> altRowStyles = FastList.newInstance(); @@ -320,6 +321,7 @@ public class ModelForm extends ModelWidg this.fieldGroupMap = parent.fieldGroupMap; this.fieldGroupList = parent.fieldGroupList; + this.lastOrderFields = parent.lastOrderFields; } } @@ -543,6 +545,10 @@ public class ModelForm extends ModelWidg 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 ModelWidg this.fieldList = sortedFields; } + if (UtilValidate.isNotEmpty(this.lastOrderFields)) { + List<ModelFormField> 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<ModelFormField> 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) { |
Free forum by Nabble | Edit this page |