From 2bed1ca2ca129af356dcfa0015e9567fce741fd4 Mon Sep 17 00:00:00 2001 From: "David E. Jones" Date: Wed, 23 Aug 2006 19:11:11 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.apache.org/repos/asf/incubator/ofbiz/trunk@434127 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/org/ofbiz/widget/form/ModelForm.java | 86 ++++++++++++++----- 1 file changed, 64 insertions(+), 22 deletions(-) diff --git a/framework/widget/src/org/ofbiz/widget/form/ModelForm.java b/framework/widget/src/org/ofbiz/widget/form/ModelForm.java index 29a20e2b7c..2ba0086e9d 100644 --- a/framework/widget/src/org/ofbiz/widget/form/ModelForm.java +++ b/framework/widget/src/org/ofbiz/widget/form/ModelForm.java @@ -1753,6 +1753,37 @@ public class ModelForm { 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 @@ public class ModelForm { 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 @@ public class ModelForm { } 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 {