svn commit: r667930 - in /ofbiz/trunk: applications/accounting/src/org/ofbiz/accounting/ applications/content/src/org/ofbiz/content/content/ applications/order/src/org/ofbiz/order/shoppingcart/ framework/base/src/base/org/ofbiz/base/util/ framework/web...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r667930 - in /ofbiz/trunk: applications/accounting/src/org/ofbiz/accounting/ applications/content/src/org/ofbiz/content/content/ applications/order/src/org/ofbiz/order/shoppingcart/ framework/base/src/base/org/ofbiz/base/util/ framework/web...

jacopoc
Author: jacopoc
Date: Sat Jun 14 23:27:15 2008
New Revision: 667930

URL: http://svn.apache.org/viewvc?rev=667930&view=rev
Log:
Added support for the skip-end attribute to form widgets of type "multi": now it is easier to add "global" form parameters to multi forms by concatenating a single form to a multi form with skip-end set to true.

Modified the way submitted multi form rows are counted: now the hidden _rowCount field in the form is no more needed because rows are counted in the ServiceMultiEventHandler (using the util methods that I have implemented in the UtilHttp class).

Modified:
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/GlEvents.java
    ofbiz/trunk/applications/content/src/org/ofbiz/content/content/UploadContentAndImage.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java
    ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/GlEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/GlEvents.java?rev=667930&r1=667929&r2=667930&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/GlEvents.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/GlEvents.java Sat Jun 14 23:27:15 2008
@@ -36,6 +36,7 @@
 import org.ofbiz.service.LocalDispatcher;
 import org.ofbiz.service.ServiceUtil;
 import org.ofbiz.service.GenericServiceException;
+import org.ofbiz.webapp.event.EventHandlerException;
 
 public class GlEvents {
     
@@ -52,10 +53,8 @@
     double reconciledBalance = 0.00;
     boolean isSelected;
     String debitCreditFlag;
-    int rowCount = 0;
-    if (ctx.containsKey("_rowCount")) {
-        rowCount = Integer.parseInt((String)ctx.get("_rowCount")); //get the number of rows
-    }
+    // The number of multi form rows is retrieved
+    int rowCount = UtilHttp.getMultiFormRowCount(ctx);
     for (int i = 0; i < rowCount; i++) {  //for calculating amount per glAccountId
         double amount = 0.00;
         String suffix = UtilHttp.MULTI_ROW_DELIMITER + i;

Modified: ofbiz/trunk/applications/content/src/org/ofbiz/content/content/UploadContentAndImage.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/content/src/org/ofbiz/content/content/UploadContentAndImage.java?rev=667930&r1=667929&r2=667930&view=diff
==============================================================================
--- ofbiz/trunk/applications/content/src/org/ofbiz/content/content/UploadContentAndImage.java (original)
+++ ofbiz/trunk/applications/content/src/org/ofbiz/content/content/UploadContentAndImage.java Sat Jun 14 23:27:15 2008
@@ -386,11 +386,11 @@
             }
             if (Debug.infoOn()) Debug.logInfo("[UploadContentAndImage]passedParams: " + passedParams, module);
 
-            String strRowCount = (String)passedParams.get("_rowCount");
-            if (UtilValidate.isEmpty(strRowCount)) {
-                strRowCount = "1";
+            // The number of multi form rows is retrieved
+            int rowCount = UtilHttp.getMultiFormRowCount(request);
+            if (rowCount < 1) {
+                rowCount = 1;
             }
-            int rowCount = Integer.parseInt(strRowCount);
             TransactionUtil.begin();
             for (int i=0; i < rowCount; i++) {
                 String suffix = "_o_" + i;

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java?rev=667930&r1=667929&r2=667930&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartEvents.java Sat Jun 14 23:27:15 2008
@@ -1700,10 +1700,6 @@
         String itemType = null;
         String itemDescription = "";
 
-        String rowCountField = null;
-        int rowCount = 0;            // number of rows of products to add
-        String DELIMITER = "_o_";    // delimiter, separating field from row number
-
         // Get the parameters as a MAP, remove the productId and quantity params.
         Map paramMap = UtilHttp.getParameterMap(request);
 
@@ -1713,24 +1709,14 @@
         String shoppingListId = request.getParameter("shoppingListId");
         String shoppingListItemSeqId = request.getParameter("shoppingListItemSeqId");
 
-        // try to get the rowCount information passed in from request
-        if (paramMap.containsKey("_rowCount")) {
-            rowCountField = (String) paramMap.remove("_rowCount");
-        } else {
-            Debug.logWarning("No _rowCount was passed in", ShoppingCartEvents.module);
-        }
-        try {
-            rowCount = Integer.parseInt(rowCountField);
-        } catch (NumberFormatException e) {
-            Debug.logWarning("Invalid value for rowCount =" + rowCountField, module);
-        }
-
+        // The number of multi form rows is retrieved
+        int rowCount = UtilHttp.getMultiFormRowCount(paramMap);
         if (rowCount < 1) {
             Debug.logWarning("No rows to process, as rowCount = " + rowCount, module);
         } else {
             for (int i = 0; i < rowCount; i++) {
                 controlDirective = null;                // re-initialize each time
-                String thisSuffix = DELIMITER + i;        // current suffix after each field id
+                String thisSuffix = UtilHttp.MULTI_ROW_DELIMITER + i;        // current suffix after each field id
 
                 // get the productId
                 if (paramMap.containsKey("productId" + thisSuffix)) {

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java?rev=667930&r1=667929&r2=667930&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartHelper.java Sat Jun 14 23:27:15 2008
@@ -440,14 +440,8 @@
         //boolean checkGlobalScope = (!context.containsKey("_checkGlobalScope"))? false :
         //        "Y".equalsIgnoreCase((String)context.get("_checkGlobalScope"));
         
-        int rowCount = 0; // parsed int value
-        try {
-            if (context.containsKey("_rowCount")) {
-                rowCount = Integer.parseInt((String)context.get("_rowCount"));
-            }
-        } catch (NumberFormatException e) {
-            //throw new EventHandlerException("Invalid value for _rowCount");
-        }
+        // The number of multi form rows is retrieved
+        int rowCount = UtilHttp.getMultiFormRowCount(context);
 
         // assume that the facility is the same for all requirements
         String facilityId = (String) context.get("facilityId_o_0");

Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java?rev=667930&r1=667929&r2=667930&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java (original)
+++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java Sat Jun 14 23:27:15 2008
@@ -1161,4 +1161,41 @@
         }
         return false;
     }
+
+    /** Returns the number or rows submitted by a multi form.
+     */
+    public static int getMultiFormRowCount(HttpServletRequest request) {
+        // The number of multi form rows is computed selecting the maximum index
+        int rowCount = 0;
+        return UtilHttp.getMultiFormRowCount(UtilHttp.getParameterMap(request));
+    }
+    /** Returns the number or rows submitted by a multi form.
+     */
+    public static int getMultiFormRowCount(Map requestMap) {
+        // The number of multi form rows is computed selecting the maximum index
+        int rowCount = 0;
+        Set<String> parameterNames = requestMap.keySet();
+        String maxRowIndex = "";
+        int rowDelimiterLength = UtilHttp.MULTI_ROW_DELIMITER.length();
+        for (String parameterName: parameterNames) {
+            int rowDelimiterIndex = (parameterName != null? parameterName.indexOf(UtilHttp.MULTI_ROW_DELIMITER): -1);
+            if (rowDelimiterIndex > 0) {
+                String thisRowIndex = parameterName.substring(rowDelimiterIndex + rowDelimiterLength);
+                if (maxRowIndex.length() < thisRowIndex.length()) {
+                    maxRowIndex = thisRowIndex;
+                } else if (maxRowIndex.length() == thisRowIndex.length() && maxRowIndex.compareTo(thisRowIndex) < 0) {
+                    maxRowIndex = thisRowIndex;
+                }
+            }
+        }
+        if (UtilValidate.isNotEmpty(maxRowIndex)) {
+            try {
+                rowCount = Integer.parseInt(maxRowIndex);
+                rowCount++; // row indexes are zero based
+            } catch (NumberFormatException e) {
+                Debug.logWarning("Invalid value for row index found: " + maxRowIndex, module);
+            }
+        }
+        return rowCount;
+    }
 }

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java?rev=667930&r1=667929&r2=667930&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java Sat Jun 14 23:27:15 2008
@@ -139,18 +139,8 @@
         boolean checkGlobalScope = request.getParameter("_checkGlobalScope") == null ? true :
                 !"N".equalsIgnoreCase(request.getParameter("_checkGlobalScope"));
 
-        // get the number of rows
-        String rowCountField = request.getParameter("_rowCount");
-        if (rowCountField == null) {
-            throw new EventHandlerException("Required field _rowCount is missing");
-        }
-
-        int rowCount = 0; // parsed int value
-        try {
-            rowCount = Integer.parseInt(rowCountField);
-        } catch (NumberFormatException e) {
-            throw new EventHandlerException("Invalid value for _rowCount");
-        }
+        // The number of multi form rows is retrieved
+        int rowCount = UtilHttp.getMultiFormRowCount(request);
         if (rowCount < 1) {
             throw new EventHandlerException("No rows to process");
         }

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=667930&r1=667929&r2=667930&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 Jun 14 23:27:15 2008
@@ -1088,7 +1088,9 @@
 
         formStringRenderer.renderFormatListWrapperClose(writer, context, this);
         
-        formStringRenderer.renderMultiFormClose(writer, context, this);
+        if (!skipEnd) {
+            formStringRenderer.renderMultiFormClose(writer, context, this);
+        }
 
     }
 

Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java?rev=667930&r1=667929&r2=667930&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java Sat Jun 14 23:27:15 2008
@@ -1123,6 +1123,11 @@
         writer.append(modelForm.getCurrentFormName(context));
         writer.append("\">");
 
+        boolean useRowSubmit = modelForm.getUseRowSubmit();
+        if (useRowSubmit) {
+            writer.append("<input type=\"hidden\" name=\"_useRowSubmit\" value=\"Y\"/>");
+        }
+
         appendWhitespace(writer);
     }
 
@@ -1149,19 +1154,6 @@
      * @see org.ofbiz.widget.form.FormStringRenderer#renderFormClose(java.io.Writer, java.util.Map, org.ofbiz.widget.form.ModelForm)
      */
     public void renderMultiFormClose(Appendable writer, Map<String, Object> context, ModelForm modelForm) throws IOException {
-        String rowCount = modelForm.getPassedRowCount(context);
-        if (UtilValidate.isEmpty(rowCount)) {
-            int rCount = modelForm.getRowCount();
-            rowCount = Integer.toString(rCount);
-        }
-        if (UtilValidate.isNotEmpty(rowCount)) {
-            writer.append("<input type=\"hidden\" name=\"_rowCount\" value=\"" + rowCount + "\"/>");
-        }
-        boolean useRowSubmit = modelForm.getUseRowSubmit();
-        if (useRowSubmit) {
-            writer.append("<input type=\"hidden\" name=\"_useRowSubmit\" value=\"Y\"/>");
-        }
-        
         Iterator submitFields = modelForm.getMultiSubmitFields().iterator();
         while (submitFields.hasNext()) {
             ModelFormField submitField = (ModelFormField)submitFields.next();