cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject svn commit: r349805 - /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Form.java
Date Tue, 29 Nov 2005 20:44:49 GMT
Author: sylvain
Date: Tue Nov 29 12:44:40 2005
New Revision: 349805

URL: http://svn.apache.org/viewcvs?rev=349805&view=rev
Log:
Fixing the fix that fixed the fix (and vice versa)

Modified:
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Form.java

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Form.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Form.java?rev=349805&r1=349804&r2=349805&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Form.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Form.java Tue Nov 29
12:44:40 2005
@@ -31,6 +31,7 @@
 import org.apache.cocoon.forms.validation.ValidationErrorAware;
 import org.apache.commons.collections.list.CursorableLinkedList;
 import org.apache.commons.lang.BooleanUtils;
+import org.apache.commons.lang.StringUtils;
 
 /**
  * A widget that serves as a container for other widgets, the top-level widget in
@@ -202,7 +203,11 @@
      * @param widget the widget
      */
     public void setSubmitWidget(Widget widget) {
-        if (this.submitWidget != null && this.submitWidget != widget) {
+        if (this.submitWidget == widget) {
+            return;
+        }
+
+        if (this.submitWidget != null) {
             throw new IllegalStateException("Submit widget already set to " + this.submitWidget
+
                     ". Cannot set also " + widget);
         }
@@ -305,37 +310,33 @@
             // Start buffering events
             this.bufferEvents = true;
 
+            this.submitWidget = null;
+
             doReadFromRequest(formContext);
 
+            // Find the submit widget, if not an action
+            // This has to occur after reading from the request, to handle stateless forms
+            // where the submit widget is recreated when the request is read (e.g. a row-action).
+            String submitId = formContext.getRequest().getParameter(SUBMIT_ID_PARAMETER);
+            if (!StringUtils.isEmpty(submitId)) {
+                // if the form has an ID, it is used as part of the submitId too and must
be removed
+                if(!StringUtils.isEmpty(this.getId())) {
+                    submitId = submitId.substring(submitId.indexOf('.')+1);
+                }
+                Widget submit = this.lookupWidget(submitId.replace('.', '/'));
+                if (submit == null) {
+                    throw new IllegalArgumentException("Invalid submit id (no such widget):
" + submitId);
+                }
+                setSubmitWidget(submit);
+            }
+
             // Fire events, still buffering them: this ensures they will be handled in the
same
             // order as they were added.
             fireEvents();
+
         } finally {
             // No need for buffering in the following phases
             this.bufferEvents = false;
-        }
-
-        // Find the submit widget, if not an action
-        // This has to occur after reading from the request, to handle stateless forms
-        // where the submit widget is recreated when the request is read (e.g. a row-action).
-        this.submitWidget = null;
-        String submitId = formContext.getRequest().getParameter(SUBMIT_ID_PARAMETER);
-        if (submitId != null && submitId.length() > 0) {
-            // if the form has an ID, it is used as part of the submitId too
-            // this has ID has to be cut off
-            if(this.getId() != null && !"".equals(this.getId())) {
-                submitId = submitId.substring(submitId.indexOf('.')+1);
-            }
-            StringTokenizer stok = new StringTokenizer(submitId, ".");
-            Widget submit = this;
-            while (stok.hasMoreTokens()) {
-                submit = submit.lookupWidget(stok.nextToken());
-                if (submit == null) {
-                    throw new IllegalArgumentException("Invalid submit id (no such widget):
" + submitId);
-                }
-            }
-
-            setSubmitWidget(submit);
         }
 
         // Notify the end of the current phase



Mime
View raw message