cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject svn commit: r177965 - in /cocoon/branches/BRANCH_2_1_X/src/blocks/forms: java/org/apache/cocoon/forms/formmodel/ java/org/apache/cocoon/forms/util/ java/org/apache/cocoon/forms/validation/ samples/forms/
Date Mon, 23 May 2005 12:32:39 GMT
Author: sylvain
Date: Mon May 23 05:32:39 2005
New Revision: 177965

URL: http://svn.apache.org/viewcvs?rev=177965&view=rev
Log:
Important optimization of AJAX refreshes. Previously, all fields were updated even if not
needed

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/util/I18nMessage.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/util/StringMessage.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/validation/ValidationError.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/carselector_form.xml
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/carselector_template.xml

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java?rev=177965&r1=177964&r2=177965&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java
Mon May 23 05:32:39 2005
@@ -55,7 +55,7 @@
         Request request = formContext.getRequest();
 
         String value = request.getParameter(fullId);
-        if (value != null && value.length() > 0) {
+        if (value != null) {
             form.setSubmitWidget(this);
 
         } else {

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java?rev=177965&r1=177964&r2=177965&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java
Mon May 23 05:32:39 2005
@@ -26,6 +26,7 @@
 import org.apache.cocoon.forms.validation.ValidationErrorAware;
 import org.apache.cocoon.xml.AttributesImpl;
 import org.apache.cocoon.xml.XMLUtils;
+import org.apache.commons.lang.ObjectUtils;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
 
@@ -145,6 +146,8 @@
             return this.value;
         }
 
+        ValidationError oldError = this.validationError;
+
         // Parse the value
         if (this.valueState == VALUE_UNPARSED) {
             doParse();
@@ -155,6 +158,12 @@
             doValidate();
         }
 
+        if (oldError != null && this.validationError == null) {
+            // The parsing process removed an existing validation error. This happens
+            // mainly when a required field is given a value.
+            getForm().addWidgetUpdate(this);
+        }
+
         return this.validationError == null ? this.value : null;
     }
 
@@ -237,6 +246,7 @@
             changed = !enteredValue.equals(newEnteredValue);
         }
         if (changed) {
+            ValidationError oldError = this.validationError;
             
             // If we have some value-changed listeners, we must make sure the current value
has been
             // parsed, to fill the event. Otherwise, we don't need to spend that extra CPU
time.
@@ -253,8 +263,12 @@
                 // will lazily compute the new value only if needed.
                 getForm().addWidgetEvent(new DeferredValueChangedEvent(this, oldValue));
             }
-            
-            getForm().addWidgetUpdate(this);
+
+            if (oldError != null) {
+                // There was a validation error, and the user entered a new value: refresh
+                // the widget, because the previous error was cleared
+                getForm().addWidgetUpdate(this);
+            }
         }
     }
 
@@ -274,7 +288,9 @@
         if (this.valueState == VALUE_PARSED) {
             doValidate();
             this.valueState = VALUE_DISPLAY_VALIDATION;
-            getForm().addWidgetUpdate(this);
+            if (this.validationError != null) {
+                getForm().addWidgetUpdate(this);
+            }
         } else if (this.valueState == VALUE_PARSE_ERROR) {
             this.valueState = VALUE_DISPLAY_PARSE_ERROR;
             getForm().addWidgetUpdate(this);
@@ -324,6 +340,7 @@
      * validation failed.
      */
     private void doValidate() {
+
         if (this.valueState != VALUE_PARSED) {
             throw new IllegalStateException("Field is not in PARSED state (" + this.valueState
+ ")");
         }
@@ -364,9 +381,11 @@
      * @param error the validation error
      */
     public void setValidationError(ValidationError error) {
-        this.validationError = error;
         this.valueState = VALUE_DISPLAY_VALIDATION;
-        getForm().addWidgetUpdate(this);
+        if (!ObjectUtils.equals(this.validationError, error)) {
+            this.validationError = error;
+            getForm().addWidgetUpdate(this);
+        }
     }
 
     public boolean isRequired() {

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/util/I18nMessage.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/util/I18nMessage.java?rev=177965&r1=177964&r2=177965&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/util/I18nMessage.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/util/I18nMessage.java
Mon May 23 05:32:39 2005
@@ -15,9 +15,12 @@
  */
 package org.apache.cocoon.forms.util;
 
+import java.util.Arrays;
+
 import org.apache.cocoon.transformation.I18nTransformer;
 import org.apache.cocoon.xml.AttributesImpl;
 import org.apache.cocoon.xml.XMLUtils;
+import org.apache.commons.lang.ObjectUtils;
 import org.apache.excalibur.xml.sax.XMLizable;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
@@ -130,5 +133,17 @@
             contentHandler.endElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TRANSLATE_ELEMENT,
"i18n:" + I18nTransformer.I18N_TRANSLATE_ELEMENT);
         }
         contentHandler.endPrefixMapping("i18n");
+    }
+    
+    public boolean equals(Object obj) {
+        if (obj instanceof I18nMessage) {
+            I18nMessage other = (I18nMessage)obj;
+            return ObjectUtils.equals(this.catalogue, other.catalogue) &&
+                   ObjectUtils.equals(this.key, other.key) &&
+                   Arrays.equals(this.keys, other.keys) &&
+                   Arrays.equals(this.parameters, other.parameters);
+        } else {
+            return false;
+        }
     }
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/util/StringMessage.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/util/StringMessage.java?rev=177965&r1=177964&r2=177965&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/util/StringMessage.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/util/StringMessage.java
Mon May 23 05:32:39 2005
@@ -15,6 +15,8 @@
  */
 package org.apache.cocoon.forms.util;
 
+import java.util.Arrays;
+
 import org.apache.excalibur.xml.sax.XMLizable;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
@@ -35,5 +37,14 @@
 
     public void toSAX(ContentHandler contentHandler) throws SAXException {
         contentHandler.characters(ch, 0, ch.length);
+    }
+    
+    public boolean equals(Object obj) {
+        if (obj instanceof StringMessage) {
+            // Compare char arrays
+            return Arrays.equals(this.ch, ((StringMessage)obj).ch);
+        } else {
+            return false;
+        }
     }
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/validation/ValidationError.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/validation/ValidationError.java?rev=177965&r1=177964&r2=177965&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/validation/ValidationError.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/validation/ValidationError.java
Mon May 23 05:32:39 2005
@@ -19,6 +19,7 @@
 import org.xml.sax.SAXException;
 import org.apache.cocoon.forms.util.I18nMessage;
 import org.apache.cocoon.forms.util.StringMessage;
+import org.apache.commons.lang.ObjectUtils;
 import org.apache.excalibur.xml.sax.XMLizable;
 
 /**
@@ -82,6 +83,14 @@
     public void generateSaxFragment(ContentHandler contentHandler) throws SAXException {
         if (saxFragment != null) {
             saxFragment.toSAX(contentHandler);
+        }
+    }
+    
+    public boolean equals(Object obj) {
+        if (obj instanceof ValidationError) {
+            return ObjectUtils.equals(this.saxFragment, ((ValidationError)obj).saxFragment);
+        } else {
+            return false;
         }
     }
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/carselector_form.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/carselector_form.xml?rev=177965&r1=177964&r2=177965&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/carselector_form.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/carselector_form.xml Mon May
23 05:32:39 2005
@@ -86,14 +86,16 @@
           modelwidget.setValue(null);
           
           // Fun with messages...
+          var msg = event.source.lookupWidget("../message");
           if (value != null) {
-            var msg = event.source.lookupWidget("../message");
             if (event.oldValue == null) {
               msg.value = "A " + makewidget.value + " " + value + " is a very good choice.";
             } else {
               msg.value = "So you prefer a " + value + " ?";
             }
-          }
+          } else {
+	      msg.value = "I see that you're undecided...";
+	  }
         </javascript>
       </fd:on-value-changed>
     </fd:field>
@@ -122,6 +124,10 @@
     <fd:output id="message">
       <fd:datatype base="string"/>
     </fd:output>
+
+    <fd:submit id="buy">
+      <fd:label>Buy it!</fd:label>
+    </fd:submit>
   
   </fd:widgets>
 

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/carselector_template.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/carselector_template.xml?rev=177965&r1=177964&r2=177965&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/carselector_template.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/forms/carselector_template.xml Mon
May 23 05:32:39 2005
@@ -73,7 +73,7 @@
             <fi:styling submit-on-change="true"/>
           </ft:widget>
           <ft:widget id="message"/>
-          <input type="submit" value="Buy it!"/>
+	  <ft:widget id="buy"/>
         </fi:items>
       </fi:group>
     </ft:form-template>



Mime
View raw message