cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t..@apache.org
Subject svn commit: rev 56962 - cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel
Date Mon, 08 Nov 2004 19:50:56 GMT
Author: tim
Date: Mon Nov  8 11:50:55 2004
New Revision: 56962

Modified:
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Union.java
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Upload.java
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetState.java
Log:
Add isValidatingValues() method to replace calls to
the isAcceptingInputs() method in validate() methods,
so we can, at some future point, separate the control
of validation from the toggling of input processing.

Remove getProcessMyRequests() and getProcessChildRequests()
methods in favor of the new method isAcceptingInputs().


Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java
(original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java
Mon Nov  8 11:50:55 2004
@@ -84,7 +84,7 @@
      *                    of the contained widgets.
      */
     public void readFromRequest(FormContext formContext) {
-        if(getCombinedState().isAcceptingInputs() && getProcessChildRequests()) {
+        if(getCombinedState().isAcceptingInputs()) {
             widgets.readFromRequest(formContext);
         }
     }
@@ -101,7 +101,7 @@
      *         extra validation rules on this containment level are ok.
      */
     public boolean validate() {
-        if (!getCombinedState().isAcceptingInputs())
+        if (!getCombinedState().isValidatingValues())
             return true;
 
         // Validate children first, then always validate self. Return combined result.

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
(original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
Mon Nov  8 11:50:55 2004
@@ -248,14 +248,6 @@
     }
 
     /**
-     * Returns whether {@link #readFromRequest(FormContext formContext)}
-     * processes the request parameter(s) for this widget.
-     */
-    public boolean getProcessMyRequests() {
-      return this.processMyRequests;
-    }
-
-    /**
      * Controls whether {@link #readFromRequest(FormContext formContext)}
      * processes the request parameter(s) for this widget.
      */
@@ -264,14 +256,6 @@
     }
 
     /**
-     * Returns whether {@link #readFromRequest(FormContext formContext)}
-     * processes the request parameter(s) for children of this widget.
-     */
-    public boolean getProcessChildRequests() {
-      return this.processChildRequests;
-    }
-
-    /**
      * Controls whether {@link #readFromRequest(FormContext formContext)}
      * processes the request parameter(s) for children of this widget.
      */
@@ -321,8 +305,8 @@
 
     public boolean validate() {
 
-        // Consider widget valid if it doesn't accept user inputs
-        if (!getCombinedState().isAcceptingInputs()) {
+        // Consider widget valid if it is not validating values.
+        if (!getCombinedState().isValidatingValues()) {
             return true;
         }
 

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java	(original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java	Mon Nov
 8 11:50:55 2004
@@ -45,7 +45,7 @@
     }
 
     public void readFromRequest(final FormContext formContext) {
-        if (!getCombinedState().isAcceptingInputs() || !getProcessMyRequests())
+        if (!getCombinedState().isAcceptingInputs())
             return;
 
         Form form = getForm();

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java
(original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java
Mon Nov  8 11:50:55 2004
@@ -101,9 +101,7 @@
         String newEnteredValue = formContext.getRequest().getParameter(getRequestParameterName());
         if (newEnteredValue != null) {
             // There is one aggregated entered value. Read it and split it.
-            if(getProcessMyRequests() == true) {
-                super.readFromRequest(formContext);
-            }
+            super.readFromRequest(formContext);
             if (this.valueState == VALUE_UNPARSED) {
                 setFieldsValues(enteredValue);
             }
@@ -111,9 +109,7 @@
             // Check if there are multiple splitted values. Read them and aggregate them.
             for (Iterator i = fields.iterator(); i.hasNext();) {
                 Field field = (Field)i.next();
-                if(getProcessChildRequests() == true) {
-                    field.readFromRequest(formContext);
-                }
+                field.readFromRequest(formContext);
                 if (field.valueState == VALUE_UNPARSED) {
                     this.valueState = VALUE_UNPARSED;
                 }
@@ -194,7 +190,7 @@
     }
 
     public boolean validate() {
-        if (!getCombinedState().isAcceptingInputs())
+        if (!getCombinedState().isValidatingValues())
             return true;
 
         if (enteredValue != null && !fieldsHaveValues()) {

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java
(original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java
Mon Nov  8 11:50:55 2004
@@ -63,7 +63,7 @@
     }
 
     public void readFromRequest(FormContext formContext) {
-        if (!getCombinedState().isAcceptingInputs() || !getProcessMyRequests())
+        if (!getCombinedState().isAcceptingInputs())
             return;
 
         validationError = null;

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java	(original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java	Mon Nov
 8 11:50:55 2004
@@ -176,7 +176,7 @@
     }
 
     public void readFromRequest(FormContext formContext) {
-        if (!getCombinedState().isAcceptingInputs() || !getProcessMyRequests())
+        if (!getCombinedState().isAcceptingInputs())
             return;
 
         String newEnteredValue = formContext.getRequest().getParameter(getRequestParameterName());
@@ -216,7 +216,7 @@
     }
 
     public boolean validate() {
-        if (!getCombinedState().isAcceptingInputs())
+        if (!getCombinedState().isValidatingValues())
             return true;
 
         if (this.valueState == VALUE_UNPARSED) {

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java	(original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java	Mon
Nov  8 11:50:55 2004
@@ -59,7 +59,7 @@
     }
 
     public boolean validate() {
-        if (!getCombinedState().isAcceptingInputs())
+        if (!getCombinedState().isValidatingValues())
             return true;
         else
             return messages.size() == 0;

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
(original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
Mon Nov  8 11:50:55 2004
@@ -73,7 +73,7 @@
     }
 
     public void readFromRequest(FormContext formContext) {
-        if (!getCombinedState().isAcceptingInputs() || !getProcessMyRequests())
+        if (!getCombinedState().isAcceptingInputs())
             return;
 
         enteredValues = formContext.getRequest().getParameterValues(getRequestParameterName());
@@ -109,7 +109,7 @@
     }
 
     public boolean validate() {
-        if (!getCombinedState().isAcceptingInputs())
+        if (!getCombinedState().isValidatingValues())
             return true;
 
         if (values != null)

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java	(original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java	Mon
Nov  8 11:50:55 2004
@@ -185,47 +185,43 @@
         if (!getCombinedState().isAcceptingInputs())
             return;
 
-        if(getProcessMyRequests() == true) {
-            // read number of rows from request, and make an according number of rows
-            String sizeParameter = formContext.getRequest().getParameter(getRequestParameterName()
+ ".size");
-            if (sizeParameter != null) {
-                int size = 0;
-                try {
-                    size = Integer.parseInt(sizeParameter);
-                } catch (NumberFormatException exc) {
-                    // do nothing
-                }
+        // read number of rows from request, and make an according number of rows
+        String sizeParameter = formContext.getRequest().getParameter(getRequestParameterName()
+ ".size");
+        if (sizeParameter != null) {
+            int size = 0;
+            try {
+                size = Integer.parseInt(sizeParameter);
+            } catch (NumberFormatException exc) {
+                // do nothing
+            }
 
-                // some protection against people who might try to exhaust the server by
supplying very large
-                // size parameters
-                if (size > 500)
-                    throw new RuntimeException("Client is not allowed to specify a repeater
size larger than 500.");
+            // some protection against people who might try to exhaust the server by supplying
very large
+            // size parameters
+            if (size > 500)
+                throw new RuntimeException("Client is not allowed to specify a repeater size
larger than 500.");
 
-                int currentSize = getSize();
-                if (currentSize < size) {
-                    for (int i = currentSize; i < size; i++) {
-                        addRow();
-                    }
-                } else if (currentSize > size) {
-                    for (int i = currentSize - 1; i >= size; i--) {
-                        removeRow(i);
-                    }
+            int currentSize = getSize();
+            if (currentSize < size) {
+                for (int i = currentSize; i < size; i++) {
+                    addRow();
+                }
+            } else if (currentSize > size) {
+                for (int i = currentSize - 1; i >= size; i--) {
+                    removeRow(i);
                 }
             }
         }
 
-        if(getProcessChildRequests() == true) {
-            // let the rows read their data from the request
-            Iterator rowIt = rows.iterator();
-            while (rowIt.hasNext()) {
-                RepeaterRow row = (RepeaterRow)rowIt.next();
-                row.readFromRequest(formContext);
-            }
+        // let the rows read their data from the request
+        Iterator rowIt = rows.iterator();
+        while (rowIt.hasNext()) {
+            RepeaterRow row = (RepeaterRow)rowIt.next();
+            row.readFromRequest(formContext);
         }
     }
 
     public boolean validate() {
-        if (!getCombinedState().isAcceptingInputs())
+        if (!getCombinedState().isValidatingValues())
             return true;
 
         boolean valid = true;

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Union.java
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Union.java	(original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Union.java	Mon Nov
 8 11:50:55 2004
@@ -84,9 +84,6 @@
     }
 
     public void readFromRequest(FormContext formContext) {
-        if (!getCombinedState().isAcceptingInputs())
-            return;
-
         // Ensure the case widget has read its value
         this.caseWidget.readFromRequest(formContext);
 
@@ -95,8 +92,7 @@
         String newValue = (String)getValue();
         if (newValue != null && !newValue.equals("")) {
 
-            if (getProcessMyRequests() == false
-                || (getForm().getSubmitWidget() == this.caseWidget && !newValue.equals(this.caseValue)))
{
+            if (getForm().getSubmitWidget() == this.caseWidget && !newValue.equals(this.caseValue))
{
                 // If submitted by the case widget and its value has changed, read the values
                 // for the previous case value. This allows to keep any already entered values
                 // despite the case change.
@@ -106,18 +102,16 @@
                 widget = getChild(newValue);
             }
 
-            if (getProcessChildRequests() == true && widget != null) {
+            if (widget != null && !getCombinedState().isAcceptingInputs()) {
                 widget.readFromRequest(formContext);
             }
         }
-        if(getProcessMyRequests() == true) {
-            this.caseValue = newValue;
-        }
+        this.caseValue = newValue;
     }
 
     // TODO: Simplify this logic.
     public boolean validate() {
-        if (!getCombinedState().isAcceptingInputs())
+        if (!getCombinedState().isValidatingValues())
             return true;
 
         Widget widget;

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Upload.java
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Upload.java	(original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Upload.java	Mon Nov
 8 11:50:55 2004
@@ -73,7 +73,7 @@
     }
 
     public void readFromRequest(FormContext formContext) {
-        if (!getCombinedState().isAcceptingInputs() || !getProcessMyRequests())
+        if (!getCombinedState().isAcceptingInputs())
             return;
 
         Object obj = formContext.getRequest().get(getRequestParameterName());
@@ -106,7 +106,7 @@
     }
 
     public boolean validate() {
-        if (!getCombinedState().isAcceptingInputs())
+        if (!getCombinedState().isValidatingValues())
             return true;
 
         if (this.part == null) {

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java	(original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java	Mon Nov
 8 11:50:55 2004
@@ -152,22 +152,10 @@
     public void setProcessRequests(boolean processRequests);
 
     /**
-     * Returns whether {@link #readFromRequest(FormContext formContext)}
-     * processes the request parameter(s) for this widget.
-     */
-    public boolean getProcessMyRequests();
-
-    /**
      * Controls whether {@link #readFromRequest(FormContext formContext)}
      * processes the request parameter(s) for this widget.
      */
     public void setProcessMyRequests(boolean processMyRequests);
-
-    /**
-     * Returns whether {@link #readFromRequest(FormContext formContext)}
-     * processes the request parameter(s) for children of this widget.
-     */
-    public boolean getProcessChildRequests();
 
     /**
      * Controls whether {@link #readFromRequest(FormContext formContext)}

Modified: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetState.java
==============================================================================
--- cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetState.java
(original)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetState.java
Mon Nov  8 11:50:55 2004
@@ -109,6 +109,15 @@
         return this.getValue() > INVISIBLE_VALUE;
     }
 
+    /**
+     * Does this state validate widget values?
+     * 
+     * @return <code>true</code> if this state validates widget values.
+     */
+    public boolean isValidatingValues() {
+        return this.getValue() == ACTIVE_VALUE;
+    }
+
 // Potential features provided by ValuedEnum that don't seem to be needed now
 //
 //    public static WidgetState stateForValue(int stateValue) {

Mime
View raw message