click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r1034737 - in /click/trunk/click: documentation/docs/ extras/src/org/apache/click/extras/control/ framework/src/org/apache/click/control/ framework/test/org/apache/click/control/
Date Sat, 13 Nov 2010 12:07:37 GMT
Author: sabob
Date: Sat Nov 13 12:07:37 2010
New Revision: 1034737

URL: http://svn.apache.org/viewvc?rev=1034737&view=rev
Log:
Improved Fields to only be processed if they have an incoming request value. CLK-722

Added:
    click/trunk/click/framework/test/org/apache/click/control/FieldTest.java
Modified:
    click/trunk/click/documentation/docs/roadmap-changes.html
    click/trunk/click/extras/src/org/apache/click/extras/control/AbstractContainerField.java
    click/trunk/click/framework/src/org/apache/click/control/Checkbox.java
    click/trunk/click/framework/src/org/apache/click/control/Field.java
    click/trunk/click/framework/src/org/apache/click/control/FileField.java

Modified: click/trunk/click/documentation/docs/roadmap-changes.html
URL: http://svn.apache.org/viewvc/click/trunk/click/documentation/docs/roadmap-changes.html?rev=1034737&r1=1034736&r2=1034737&view=diff
==============================================================================
--- click/trunk/click/documentation/docs/roadmap-changes.html (original)
+++ click/trunk/click/documentation/docs/roadmap-changes.html Sat Nov 13 12:07:37 2010
@@ -174,6 +174,12 @@ Action support and light-weight stateful
       </div>
       <ul style="padding: 0em; margin-left:0em;margin-bottom: 2em">
           <li class="change">
+              Improve fields to only be processed if there is a matching request
+              parameter. This improvement streamlines dynamic forms since fields
+              added at runtime won't bind their values or be validated
+            [<a target="_blank" href="https://issues.apache.org/jira/browse/CLK-722">CLK-722</a>].
+          </li>
+          <li class="change">
             Added automapping support for GAE with a caveat that page templates
             must be placed under the folders <tt>page</tt> or <tt>pages</tt>.
             This issue was raised by Ke Sun

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/AbstractContainerField.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/AbstractContainerField.java?rev=1034737&r1=1034736&r2=1034737&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/AbstractContainerField.java
(original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/AbstractContainerField.java
Sat Nov 13 12:07:37 2010
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import org.apache.click.Context;
 
 import org.apache.click.Control;
 import org.apache.click.control.Container;
@@ -302,7 +303,32 @@ public abstract class AbstractContainerF
      */
     @Override
     public boolean onProcess() {
-        boolean continueProcessing = super.onProcess();
+        boolean performProcessing = true;
+
+        if (isDisabled()) {
+            Context context = getContext();
+
+            // Switch off disabled property if field has an incoming request
+            // parameter.
+            if (context.hasRequestParameter(getName())) {
+                setDisabled(false);
+
+            } else {
+                // If field is disabled skip processing and validation
+                performProcessing = false;
+            }
+        }
+
+        if (performProcessing) {
+            bindRequestValue();
+
+            if (getValidate()) {
+                validate();
+            }
+            dispatchActionEvent();
+        }
+
+        boolean continueProcessing = true;
 
         if (hasControls()) {
             for (Control control : getControls()) {

Modified: click/trunk/click/framework/src/org/apache/click/control/Checkbox.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Checkbox.java?rev=1034737&r1=1034736&r2=1034737&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/Checkbox.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/Checkbox.java Sat Nov 13 12:07:37
2010
@@ -19,6 +19,7 @@
 package org.apache.click.control;
 
 import java.text.MessageFormat;
+import org.apache.click.Context;
 
 import org.apache.click.util.HtmlStringBuffer;
 
@@ -235,6 +236,40 @@ public class Checkbox extends Field {
     }
 
     /**
+     * Process the request Context setting the checked value if selected
+     * and invoking the control's listener if defined.
+     *
+     * @return true to continue Page event processing, false otherwise
+     */
+    @Override
+    public boolean onProcess() {
+        if (isDisabled()) {
+            Context context = getContext();
+
+            // Switch off disabled property if control has incoming request
+            // parameter. Normally this means the field was enabled via JS
+            if (context.hasRequestParameter(getName())) {
+                setDisabled(false);
+            } else {
+                // If field is disabled skip process event
+                return true;
+            }
+        }
+
+        // In Html an unchecked Checkbox does not submit it's name/value so we
+        // always validate and dispatch registered events
+        bindRequestValue();
+
+        if (getValidate()) {
+            validate();
+        }
+
+        dispatchActionEvent();
+
+        return true;
+    }
+
+    /**
      * Render the HTML representation of the Checkbox.
      *
      * @see #toString()

Modified: click/trunk/click/framework/src/org/apache/click/control/Field.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Field.java?rev=1034737&r1=1034736&r2=1034737&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/Field.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/Field.java Sat Nov 13 12:07:37
2010
@@ -1091,26 +1091,20 @@ public abstract class Field extends Abst
      */
     @Override
     public boolean onProcess() {
-        if (isDisabled()) {
-            Context context = getContext();
+        Context context = getContext();
 
-            // Switch off disabled property if control has incoming request
-            // parameter. Normally this means the field was enabled via JS
-            if (context.hasRequestParameter(getName())) {
-                setDisabled(false);
-            } else {
-                // If field is disabled skip process event
-                return true;
-            }
-        }
+        if (context.hasRequestParameter(getName())) {
+            // Only process field if it participated in the incoming request
+            setDisabled(false);
 
-        bindRequestValue();
+            bindRequestValue();
 
-        if (getValidate()) {
-            validate();
-        }
+            if (getValidate()) {
+                validate();
+            }
 
-        dispatchActionEvent();
+            dispatchActionEvent();
+        }
 
         return true;
     }

Modified: click/trunk/click/framework/src/org/apache/click/control/FileField.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/FileField.java?rev=1034737&r1=1034736&r2=1034737&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/FileField.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/FileField.java Sat Nov 13 12:07:37
2010
@@ -19,6 +19,7 @@
 package org.apache.click.control;
 
 import java.text.MessageFormat;
+import org.apache.click.Context;
 
 import org.apache.click.util.HtmlStringBuffer;
 
@@ -260,6 +261,33 @@ public class FileField extends Field {
     }
 
     /**
+     * Overrides onProcess to use {@link org.apache.click.Context#getFileItem(java.lang.String)}.
+     *
+     * @see org.apache.click.control.Field#onProcess()
+     *
+     * @return true to continue Page event processing or false otherwise
+     */
+    @Override
+    public boolean onProcess() {
+        Context context = getContext();
+
+        if (context.getFileItemMap().containsKey(getName())) {
+            // Only process field if it participated in the incoming request
+            setDisabled(false);
+
+            bindRequestValue();
+
+            if (getValidate()) {
+                validate();
+            }
+
+            dispatchActionEvent();
+        }
+
+        return true;
+    }
+
+    /**
      * Render the HTML representation of the FileField.
      *
      * @see #toString()
@@ -321,8 +349,8 @@ public class FileField extends Field {
         setError(null);
 
         if (isRequired()) {
-            FileItem fileItem = getFileItem();
-            if (fileItem == null || StringUtils.isBlank(fileItem.getName())) {
+            FileItem localFileItem = getFileItem();
+            if (localFileItem == null || StringUtils.isBlank(localFileItem.getName())) {
                 setErrorMessage("file-required-error");
             }
         }

Added: click/trunk/click/framework/test/org/apache/click/control/FieldTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/FieldTest.java?rev=1034737&view=auto
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/FieldTest.java (added)
+++ click/trunk/click/framework/test/org/apache/click/control/FieldTest.java Sat Nov 13 12:07:37
2010
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.control;
+
+import junit.framework.TestCase;
+import org.apache.click.MockContext;
+import org.apache.click.servlet.MockRequest;
+
+/**
+ *
+ */
+public class FieldTest extends TestCase {
+
+    /**
+     * Test Field onProcess.
+     */
+    public void testOnProcess() {
+        MockContext context = MockContext.initContext();
+        MockRequest request = context.getMockRequest();
+
+        Field field = new TextField("text");
+        field.setRequired(true);
+
+        assertEquals("", field.getValue());
+
+        // Test with valid request parameter
+        String expectedValue = "textvalue";
+
+        request.setParameter("text", expectedValue);
+
+        field.onProcess();
+
+        // Perform tests
+        assertEquals(expectedValue, field.getValue());
+        assertTrue(field.isValid());
+
+        // Test with empty  request parameter
+        expectedValue = "";
+        request.setParameter("text", expectedValue);
+
+        field.onProcess();
+
+        // Perform tests
+        assertEquals(expectedValue, field.getValue());
+        // Since the field value is empty, test that required validation occurred
+        assertFalse(field.isValid());
+    }
+
+    /**
+     * Test Field onProcess if the Field's request parameter is not available.
+     */
+    public void testOnProcessWithoutRequestParameter() {
+        MockContext context = MockContext.initContext();
+
+        Field field = new TextField("text");
+        field.setRequired(true);
+
+        assertEquals("", field.getValue());
+
+        String expectedValue = "";
+
+        field.onProcess();
+
+        assertEquals(expectedValue, field.getValue());
+        assertTrue(field.isValid());
+    }
+}



Mime
View raw message