cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r180096 - in /cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms: flow/javascript/Form.js formmodel/AbstractContainerWidget.java formmodel/AbstractWidget.java formmodel/ContainerWidget.java formmodel/Form.java formmodel/MultiValueField.java formmodel/Repeater.java generation/JXMacrosHelper.java generation/jx-macros.xml
Date Sun, 05 Jun 2005 14:36:03 GMT
Author: reinhard
Date: Sun Jun  5 07:36:02 2005
New Revision: 180096

URL: http://svn.apache.org/viewcvs?rev=180096&view=rev
Log:
make Form and Repeater ValidationErrorAware; fix unbalanced SAX-events in jx-macro.xml caused
by Ajax implementation; minor code reformatting to make Eclipse happier

Modified:
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/flow/javascript/Form.js
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/ContainerWidget.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Form.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Repeater.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java
    cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/flow/javascript/Form.js
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/flow/javascript/Form.js?rev=180096&r1=180095&r2=180096&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/flow/javascript/Form.js (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/flow/javascript/Form.js Sun Jun
 5 07:36:02 2005
@@ -170,6 +170,14 @@
     FOM_Cocoon.suicide();
 }
 
+Form.prototype.setValidationError = function(error) {
+    this.form.setValidationError(error);
+}
+
+Form.prototype.getValidationError = function() {
+    return this.form.getValidationError();
+}
+
 Form.prototype.createBinding = function(bindingURI) {
     var bindingManager = null;
     var source = null;

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java?rev=180096&r1=180095&r2=180096&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java
(original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java
Sun Jun  5 07:36:02 2005
@@ -19,6 +19,7 @@
 import java.util.Locale;
 
 import org.apache.cocoon.forms.FormContext;
+import org.apache.cocoon.forms.validation.ValidationError;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
@@ -33,6 +34,11 @@
      * List of contained widgets.
      */
     protected WidgetList widgets;
+    
+    /**
+     * validation errors on container widgets
+     */
+    protected ValidationError validationError;    
 
     /**
      * Constructs AbstractContainerWidget
@@ -123,5 +129,6 @@
         if (getCombinedState().isDisplayingValues()) {
             widgets.generateSaxFragment(contentHandler, locale);
         }
-    }
+    }    
+    
 }

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java?rev=180096&r1=180095&r2=180096&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java Sun
Jun  5 07:36:02 2005
@@ -159,9 +159,8 @@
     public WidgetState getCombinedState() {
         if (this.parent == null) {
             return this.state;
-        } else {
-            return WidgetState.strictest(this.state, this.parent.getCombinedState());
-        }
+        } 
+        return WidgetState.strictest(this.state, this.parent.getCombinedState());
     }
 
     public String getRequestParameterName() {
@@ -276,13 +275,11 @@
     public boolean removeValidator(WidgetValidator validator) {
         if (this.validators != null) {
             return this.validators.remove(validator);
-        } else {
-            return false;
         }
+        return false;
     }
 
     public boolean validate() {
-
         // Consider widget valid if it is not validating values.
         if (!getCombinedState().isValidatingValues()) {
             return true;
@@ -292,24 +289,25 @@
         if (!getDefinition().validate(this)) {
             // Failed
             return false;
-        } else {
-            // Definition successful, test local validators
-            if (this.validators == null) {
-                // No local validators
-                return true;
-            } else {
-                // Iterate on local validators
-                Iterator iter = this.validators.iterator();
-                while(iter.hasNext()) {
-                    WidgetValidator validator = (WidgetValidator)iter.next();
-                    if (!validator.validate(this)) {
-                        return false;
-                    }
-                }
-                // All local iterators successful
-                return true;
+        } 
+        // Definition successful, test local validators
+        if (this.validators == null) {
+            // No local validators
+            return true;
+        }
+        
+        // Iterate on local validators
+        Iterator iter = this.validators.iterator();
+        while(iter.hasNext()) {
+            WidgetValidator validator = (WidgetValidator)iter.next();
+            if (!validator.validate(this)) {
+                return false;
             }
         }
+        
+        // All local iterators successful
+        return true;
+
     }
 
     /**

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/ContainerWidget.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/ContainerWidget.java?rev=180096&r1=180095&r2=180096&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/ContainerWidget.java
(original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/ContainerWidget.java
Sun Jun  5 07:36:02 2005
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 package org.apache.cocoon.forms.formmodel;
+
 import java.util.Iterator;
 
 /**

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=180096&r1=180095&r2=180096&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 Sun Jun  5
07:36:02 2005
@@ -28,6 +28,8 @@
 import org.apache.cocoon.forms.event.ProcessingPhaseListener;
 import org.apache.cocoon.forms.event.WidgetEvent;
 import org.apache.cocoon.forms.event.WidgetEventMulticaster;
+import org.apache.cocoon.forms.validation.ValidationError;
+import org.apache.cocoon.forms.validation.ValidationErrorAware;
 import org.apache.commons.collections.list.CursorableLinkedList;
 import org.apache.commons.lang.BooleanUtils;
 
@@ -39,7 +41,7 @@
  * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
  * @version $Id$
  */
-public class Form extends AbstractContainerWidget {
+public class Form extends AbstractContainerWidget implements ValidationErrorAware {
 
     private final FormDefinition definition;
 
@@ -317,8 +319,25 @@
         // let all individual widgets read their value from the request object
         super.readFromRequest(formContext);
     }
+    
+    /**
+     * Set a validation error on this field. This allows the form to be externally marked
as invalid by
+     * application logic.
+     *
+     * @param error the validation error
+     */
+    public ValidationError getValidationError() {
+        return this.validationError;
+    }
 
     /**
+     * set a validation error
+     */
+    public void setValidationError(ValidationError error) {
+        this.validationError = error;
+    }
+    
+    /**
      * Performs validation phase of form processing.
      */
     public boolean validate() {
@@ -342,7 +361,7 @@
             return this.endProcessing.booleanValue();
         }
 
-        return this.isValid;
+        return this.isValid && this.validationError == null;
     }
 
     private static final String FORM_EL = "form";

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/MultiValueField.java?rev=180096&r1=180095&r2=180096&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
(original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
Sun Jun  5 07:36:02 2005
@@ -117,11 +117,12 @@
         if (!getCombinedState().isValidatingValues())
             return true;
 
-        if (values != null)
+        if (values != null) {
             validationError = definition.getDatatype().validate(values, new ExpressionContextImpl(this));
-        else
+        }
+        else {
             validationError = new ValidationError(new I18nMessage("multivaluefield.conversionfailed",
Constants.I18N_CATALOGUE));
-
+        }
         return validationError == null ? super.validate() : false;
     }
 

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Repeater.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Repeater.java?rev=180096&r1=180095&r2=180096&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Repeater.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/Repeater.java Sun Jun
 5 07:36:02 2005
@@ -23,6 +23,8 @@
 import org.apache.cocoon.forms.Constants;
 import org.apache.cocoon.forms.FormContext;
 import org.apache.cocoon.forms.event.WidgetEvent;
+import org.apache.cocoon.forms.validation.ValidationError;
+import org.apache.cocoon.forms.validation.ValidationErrorAware;
 import org.apache.cocoon.xml.AttributesImpl;
 import org.apache.cocoon.xml.XMLUtils;
 import org.xml.sax.ContentHandler;
@@ -41,11 +43,11 @@
  * 
  * @version $Id$
  */
-public class Repeater extends AbstractWidget 
-//implements ContainerWidget 
+public class Repeater extends AbstractWidget implements ValidationErrorAware //, ContainerWidget

 {
     private final RepeaterDefinition definition;
     private final List rows = new ArrayList();
+    protected ValidationError validationError;
 
     public Repeater(RepeaterDefinition repeaterDefinition) {
         super(repeaterDefinition);
@@ -131,9 +133,8 @@
         if (result == null) {
             throw new RuntimeException("Could not find a parent row for widget " + widget);
 
-        } else {
-            return (Repeater.RepeaterRow)result;
         }
+        return (Repeater.RepeaterRow)result;
     }
     
     /**
@@ -257,7 +258,7 @@
             RepeaterRow row = (RepeaterRow)rowIt.next();
             valid = valid & row.validate();
         }
-        return valid ? super.validate() : false;
+        return (valid ? super.validate() : false) && this.validationError == null;
     }
 
 
@@ -335,6 +336,23 @@
         contentHandler.startElement(Constants.INSTANCE_NS, REPEATER_SIZE_EL, Constants.INSTANCE_PREFIX_COLON
+ REPEATER_SIZE_EL, attrs);
         contentHandler.endElement(Constants.INSTANCE_NS, REPEATER_SIZE_EL, Constants.INSTANCE_PREFIX_COLON
+ REPEATER_SIZE_EL);
     }
+    
+    /**
+     * Set a validation error on this field. This allows repeaters be externally marked as
invalid by
+     * application logic.
+     *
+     * @param error the validation error
+     */
+    public ValidationError getValidationError() {
+        return this.validationError;
+    }
+
+    /**
+     * set a validation error
+     */
+    public void setValidationError(ValidationError error) {
+        this.validationError = error;
+    }
 
     public class RepeaterRow extends AbstractContainerWidget {
 
@@ -399,4 +417,5 @@
             throw new UnsupportedOperationException("Widget " + this.getRequestParameterName()
+ " doesn't handle events.");
         }
     }
+
 }

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java?rev=180096&r1=180095&r2=180096&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java
(original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/JXMacrosHelper.java
Sun Jun  5 07:36:02 2005
@@ -202,6 +202,21 @@
         error.generateSaxFragment(pipe);
         pipe.endElement(Constants.INSTANCE_NS, VALIDATION_ERROR, Constants.INSTANCE_PREFIX_COLON
+ VALIDATION_ERROR);
     }
+    
+    /**
+     * Flush the validation error that has been stored.
+     *
+     * @param validation error that is terminated
+     * @throws SAXException
+     */
+    public void flushRoot(ValidationError error) throws SAXException {
+        Object stackObj = stack.pop();
+        if (stackObj != error) {
+            throw new IllegalStateException("Flushing on wrong validation error (expected
" + stackObj +
+                                            ", got " + error + ")");
+        }
+        ((RootBufferingPipe) stack.pop()).flushRoot();
+    }    
 
     public boolean isValidationError(Object object) {
         return object instanceof ValidationError;
@@ -255,7 +270,7 @@
 
     /**
      * A SAX pipe that buffers the <code>endElement()</code> event of the root
element.
-     * This is needed by the generator version of the Woody transformer (see woody-jxmacros.xml).
+     * This is needed by the generator version of the FormsTransformer (see jx-macros.xml).
      *
      * @version $Id$
      */

Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml?rev=180096&r1=180095&r2=180096&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/generation/jx-macros.xml Sun Jun
 5 07:36:02 2005
@@ -194,11 +194,9 @@
       <jx:set var="widget" value="${cformsHelper.getWidget(widget, id)}"/>
       <jx:set var="validationError" value="${widget.getValidationError()}"/>
       <jx:if test="${cformsHelper.isValidationError(validationError)}">
-        <fi:validation-error>
           <jx:set var="cformsDummy" value="${cformsHelper.generateValidationError(validationError)}"/>
             <jx:evalBody/>
           <jx:set var="cformsDummy" value="${cformsHelper.flushRoot(validationError)}"/>
-        </fi:validation-error>
       </jx:if>
     </jx:macro>
 



Mime
View raw message