You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jo...@apache.org on 2006/08/23 21:11:12 UTC

svn commit: r434127 - /incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java

Author: jonesde
Date: Wed Aug 23 12:11:11 2006
New Revision: 434127

URL: http://svn.apache.org/viewvc?rev=434127&view=rev
Log:
Changed form widget to look at VIEW_INDEX/SIZE and the normal field name in the parameters map if it doesn't find it in the root context

Modified:
    incubator/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java

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?rev=434127&r1=434126&r2=434127&view=diff
==============================================================================
--- 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 Wed Aug 23 12:11:11 2006
@@ -1753,6 +1753,37 @@
         return field;
     }
 
+    public int getPaginateIndex(Map context) {
+        String field = this.getPaginateIndexField(context);
+        
+        int viewIndex = 0;
+        try {
+            Object value = context.get(field);
+
+            if (value == null) {
+        	// try parameters.VIEW_INDEX as that is an old OFBiz convention
+        	Map parameters = (Map) context.get("parameters");
+        	if (parameters != null) {
+        	    value = parameters.get("VIEW_INDEX");
+        	    
+        	    if (value == null) {
+        		value = parameters.get(field);
+        	    }
+        	}
+            }
+
+            if (value instanceof Integer) { 
+                viewIndex = ((Integer) value).intValue();
+            } else if (value instanceof String) { 
+                viewIndex = Integer.parseInt((String) value);
+            }
+        } catch (Exception e) {
+            Debug.logWarning(e, "Error getting paginate view index: " + e.toString(), module);
+        }
+        
+        return viewIndex;
+    }
+
     public String getPaginateSizeField(Map context) {
         String field = this.paginateSizeField.expandString(context);
         if (UtilValidate.isEmpty(field)) {
@@ -1761,6 +1792,37 @@
         return field;
     }
 
+    public int getPaginateSize(Map context) {
+        String field = this.getPaginateSizeField(context);
+        
+        int viewSize = DEFAULT_PAGE_SIZE;
+        try {
+            Object value = context.get(field);
+            
+            if (value == null) {
+        	// try parameters.VIEW_SIZE as that is an old OFBiz convention
+        	Map parameters = (Map) context.get("parameters");
+        	if (parameters != null) {
+        	    value = parameters.get("VIEW_SIZE");
+        	    
+        	    if (value == null) {
+        		value = parameters.get(field);
+        	    }
+        	}
+            }
+            
+            if (value instanceof Integer) { 
+                viewSize = ((Integer) value).intValue();
+            } else if (value instanceof String) { 
+                viewSize = Integer.parseInt((String) value);
+            }
+        } catch (Exception e) {
+            Debug.logWarning(e, "Error getting paginate view size: " + e.toString(), module);
+        }
+        
+        return viewSize;
+    }
+
     public String getPaginatePreviousLabel(Map context) {
         String field = this.paginatePreviousLabel.expandString(context);
         if (UtilValidate.isEmpty(field)) {
@@ -1921,29 +1983,9 @@
         }
         
         if (paginate) {
-            viewIndex = 0;
-            viewSize = DEFAULT_PAGE_SIZE;
-            try {
-                Object value = context.get(getPaginateIndexField(context));
-                if (value instanceof Integer) { 
-                    viewIndex = ((Integer) value).intValue();
-                } else if (value instanceof String) { 
-                    viewIndex = Integer.parseInt((String) value);
-                }
-            } catch (Exception e) {
-                Debug.logWarning(e, "Error getting paginate view index: " + e.toString(), module);
-            }
+            viewIndex = this.getPaginateIndex(context);
+            viewSize = this.getPaginateSize(context);
             
-            try {
-                Object value = context.get(getPaginateSizeField(context));
-                if (value instanceof Integer) { 
-                    viewSize = ((Integer) value).intValue();
-                } else if (value instanceof String) { 
-                    viewSize = Integer.parseInt((String) value);
-                }
-            } catch (Exception e) {
-                Debug.logWarning(e, "Error getting paginate view size: " + e.toString(), module);
-            }
             lowIndex = viewIndex * viewSize;
             highIndex = (viewIndex + 1) * viewSize;
         } else {