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.


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1307784 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jacques Le Roux
2012-03-31 12:10:07 +00:00
parent e1a03aee17
commit bf2feb63bd
2 changed files with 36 additions and 0 deletions
@@ -133,6 +133,7 @@ public class ModelForm extends ModelWidget {
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 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<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) {