Author: jacopoc
Date: Tue Oct 31 00:14:14 2006
New Revision: 469408

URL: http://svn.apache.org/viewvc?view=rev&rev=469408
Log:
Following David Jones's suggestions in OFBIZ-364, I've added a new attribute to 
the "form" element:
override-list-size
It can be used to pass a custom list size (differnt from the actual list size) 
that can be useful for pagination purposes under some circumstances.
The attribute can accept the ${} notation.

Modified:
    
incubator/ofbiz/trunk/applications/product/webapp/facility/facility/FacilityForms.xml
    incubator/ofbiz/trunk/framework/widget/dtd/widget-form.xsd
    
incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java

Modified: 
incubator/ofbiz/trunk/applications/product/webapp/facility/facility/FacilityForms.xml
URL: 
http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/product/webapp/facility/facility/FacilityForms.xml?view=diff&rev=469408&r1=469407&r2=469408
==============================================================================
--- 
incubator/ofbiz/trunk/applications/product/webapp/facility/facility/FacilityForms.xml
 (original)
+++ 
incubator/ofbiz/trunk/applications/product/webapp/facility/facility/FacilityForms.xml
 Tue Oct 31 00:14:14 2006
@@ -95,8 +95,8 @@
             <submit button-type="button"/>
         </field>
     </form>
-    <form name="ListFacilityInventoryByProduct" type="list" 
-            target="" title="" list-name="inventoryByProduct" 
paginate-target="${facilityInventoryByProductScreen}"
+    <form name="ListFacilityInventoryByProduct" type="list" target="" title="" 
override-list-size="${overrideListSize}"
+            list-name="inventoryByProduct" 
paginate-target="${facilityInventoryByProductScreen}"
             default-title-style="tableheadtext" 
default-widget-style="tabletext" default-tooltip-style="tabletext">
         <field name="items" title="${uiLabelMap.ProductProductId}" 
widget-style="buttontext">
             <hyperlink 
target="EditFacilityInventoryItems?productId=${productId}&amp;facilityId=${facilityId}"
 description="${productId}"/>     

Modified: incubator/ofbiz/trunk/framework/widget/dtd/widget-form.xsd
URL: 
http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/widget/dtd/widget-form.xsd?view=diff&rev=469408&r1=469407&r2=469408
==============================================================================
--- incubator/ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original)
+++ incubator/ofbiz/trunk/framework/widget/dtd/widget-form.xsd Tue Oct 31 
00:14:14 2006
@@ -113,6 +113,9 @@
         <xs:attribute type="xs:string" name="paginate-index-field">
             <xs:annotation><xs:documentation>The name of the parameter that 
specifies what the current page is in a list form with multiple pages. The 
default is VIEW_INDEX Accepts ${} notation.</xs:documentation></xs:annotation>
         </xs:attribute>
+        <xs:attribute type="xs:string" name="override-list-size">
+            <xs:annotation><xs:documentation>The total number of rows in the 
original list (used for pagination). If not specified, the size of the list 
will be used. Accepts ${} notation.</xs:documentation></xs:annotation>
+        </xs:attribute>
         <xs:attribute type="xs:string" name="paginate-previous-label">
             <xs:annotation><xs:documentation>Text to display for the 
[Previous] button in a form with pagination. Defaults to "Previous". Accepts 
${} notation.</xs:documentation></xs:annotation>
         </xs:attribute>

Modified: 
incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
URL: 
http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?view=diff&rev=469408&r1=469407&r2=469408
==============================================================================
--- 
incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java 
(original)
+++ 
incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java 
Tue Oct 31 00:14:14 2006
@@ -81,6 +81,7 @@
     protected FlexibleStringExpander paginateTarget;
     protected FlexibleStringExpander paginateIndexField;
     protected FlexibleStringExpander paginateSizeField;
+    protected FlexibleStringExpander overrideListSize;
     protected FlexibleStringExpander paginatePreviousLabel;
     protected FlexibleStringExpander paginateNextLabel;
     protected String paginateTargetAnchor;
@@ -98,7 +99,7 @@
     protected boolean skipStart = false;
     protected boolean skipEnd = false;
     protected boolean hideHeader = false;
-    protected boolean overridenFormListSize = false;
+    protected boolean overridenListSize = false;
 
     protected List altTargets = new LinkedList();
     protected List autoFieldsServices = new LinkedList();
@@ -342,6 +343,9 @@
         if (this.paginateSizeField == null || 
formElement.hasAttribute("paginate-size-field")) {
             
setPaginateSizeField(formElement.getAttribute("paginate-size-field"));
         }
+        if (this.overrideListSize == null || 
formElement.hasAttribute("override-list-size")) {
+            this.overrideListSize = new 
FlexibleStringExpander(formElement.getAttribute("override-list-size"));
+        }
         if (this.paginatePreviousLabel == null || 
formElement.hasAttribute("paginate-previous-label")) {
             this.paginatePreviousLabel = new 
FlexibleStringExpander(formElement.getAttribute("paginate-previous-label"));
         }
@@ -1115,7 +1119,7 @@
         int highIndex = ((Integer) context.get("highIndex")).intValue();
 
         // we're passed a subset of the list, so use (0, viewSize) range
-        if (isOverridenFormListSize()) {
+        if (isOverridenListSize()) {
             lowIndex = 0;
             highIndex = ((Integer) context.get("viewSize")).intValue();
         }
@@ -1278,7 +1282,7 @@
             if ((itemIndex + 1) < highIndex) {
                 highIndex = itemIndex + 1;
                 // if list size is overridden, use full listSize
-                context.put("highIndex", new Integer(isOverridenFormListSize() 
? listSize : highIndex));
+                context.put("highIndex", new Integer(isOverridenListSize() ? 
listSize : highIndex));
             }
             context.put("actualPageSize", new Integer(highIndex - lowIndex));
             
@@ -1879,8 +1883,8 @@
         return this.skipEnd;
     }
 
-    public boolean isOverridenFormListSize() {
-        return this.overridenFormListSize;
+    public boolean isOverridenListSize() {
+        return this.overridenListSize;
     }
 
     public void setSkipStart(boolean val) {
@@ -1899,8 +1903,8 @@
         paginate = val;
     }
 
-    public void setOverridenFormListSize(boolean overridenFormListSize) {
-        this.overridenFormListSize = overridenFormListSize;
+    public void setOverridenListSize(boolean overridenListSize) {
+        this.overridenListSize = overridenListSize;
     }
 
     /**
@@ -1973,20 +1977,14 @@
         return fieldList;
     }
 
-    private int getOverrideFormListSize(Map context) {
+    private int getOverrideListSize(Map context) {
         int listSize = 0;
-        Object overrideFormListSize = context.get("overrideFormListSize");
-        if (overrideFormListSize != null) {
-            if (overrideFormListSize instanceof Number) {
-                listSize = ((Number) overrideFormListSize).intValue();
-            } else if (overrideFormListSize instanceof String) {
-                try {
-                    listSize = Integer.parseInt((String) overrideFormListSize);
-                } catch (NumberFormatException e) {
-                    Debug.logError(e, "Error getting override list size", 
module);
-                }
-            } else {
-                Debug.logError("Error getting override list size: Unable to 
determine size from input [" + overrideFormListSize + "]", module);
+        String size = this.overrideListSize.expandString(context);
+        if (!UtilValidate.isEmpty(size)) {
+            try {
+                listSize = Integer.parseInt(size);
+            } catch (NumberFormatException e) {
+                Debug.logError(e, "Error getting override list size from value 
" + size, module);
             }
         }
         return listSize;
@@ -1999,9 +1997,9 @@
         int lowIndex = 0;
         int highIndex = 0;
 
-        listSize = getOverrideFormListSize(context);
+        listSize = getOverrideListSize(context);
         if (listSize > 0) {
-            setOverridenFormListSize(true);
+            setOverridenListSize(true);
         } else if (entryList instanceof EntityListIterator) {
             EntityListIterator iter = (EntityListIterator) entryList;   
             try {


Reply via email to