click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r925555 - in /click/trunk/click/framework/src/org/apache/click: control/ActionButton.java control/Field.java control/Radio.java control/RadioGroup.java control/Submit.java util/ContainerUtils.java
Date Sat, 20 Mar 2010 06:14:12 GMT
Author: sabob
Date: Sat Mar 20 06:14:11 2010
New Revision: 925555

URL: http://svn.apache.org/viewvc?rev=925555&view=rev
Log:
improved disabled behavior. CLK-646

Modified:
    click/trunk/click/framework/src/org/apache/click/control/ActionButton.java
    click/trunk/click/framework/src/org/apache/click/control/Field.java
    click/trunk/click/framework/src/org/apache/click/control/Radio.java
    click/trunk/click/framework/src/org/apache/click/control/RadioGroup.java
    click/trunk/click/framework/src/org/apache/click/control/Submit.java
    click/trunk/click/framework/src/org/apache/click/util/ContainerUtils.java

Modified: click/trunk/click/framework/src/org/apache/click/control/ActionButton.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/ActionButton.java?rev=925555&r1=925554&r2=925555&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/ActionButton.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/ActionButton.java Sat Mar 20
06:14:11 2010
@@ -484,11 +484,24 @@ public class ActionButton extends Button
      * ActionButton was clicked, and if an action callback listener was set
      * this will be invoked.
      *
-     * @see org.apache.click.Control#onProcess()
+     * @see org.apache.click.control.Field#onProcess()
      *
      * @return true to continue Page event processing or false otherwise
      */
     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;
+            }
+        }
+
         bindRequestValue();
 
         if (isClicked()) {

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=925555&r1=925554&r2=925555&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 Mar 20 06:14:11
2010
@@ -18,6 +18,7 @@
  */
 package org.apache.click.control;
 
+import org.apache.click.Context;
 import org.apache.click.Control;
 import org.apache.click.Page;
 import org.apache.commons.lang.StringUtils;
@@ -296,10 +297,8 @@ public abstract class Field extends Abst
     /**
      * Return true if the Field is disabled. The Field will also be disabled
      * if the parent FieldSet or Form is disabled.
-     * <p/>
-     * <b>Important Note</b>: disabled fields will not submit their values in
-     * a HTML form POST. This may cause validation issues in a form submission.
-     * Please note this is a HTML limitation and is not due to Click.
+     *
+     * @see #setDisabled(boolean)
      *
      * @return true if the Field is disabled
      */
@@ -329,11 +328,23 @@ public abstract class Field extends Abst
     }
 
     /**
-     * Set the Field disabled flag.
+     * Set the Field disabled flag. Disabled fields are not processed nor
+     * validated and their action event is not fired.
      * <p/>
-     * <b>Important Note</b>: disabled fields will not submit their values in
-     * a HTML form POST. This may cause validation issues in a form submission.
-     * Please note this is a HTML limitation and is not due to Click.
+     * <b>Important Note</b>: an HTML form POST does not submit disabled fields
+     * values. Similarly disabled Click fields do not get processed or validated.
+     * However, JavaScript is often used to <tt>enable</tt> fields prior to
+     * submission. Click is smart enough to recognize when a field was enabled
+     * this way by checking if the field has an incoming request parameter.
+     * If a field is disabled but has an incoming request parameter, Click will
+     * <tt>"enable"</tt> the field and process it.
+     * <p/>
+     * <b>Caveat</b>: Unfortunately the above behavior does not apply to
+     * {@link Checkbox} and {@link Radio} buttons. An HTML form POST for a
+     * <tt>disabled</tt> checkbox/radio is the same as for an <tt>unchecked</tt>
+     * checkbox/radio. In neither case is a value submitted to the server and
+     * Click cannot make the distinction whether the checkbox/radio is disabled
+     * or unchecked.
      *
      * @param disabled the Field disabled flag
      */
@@ -1008,6 +1019,12 @@ public abstract class Field extends Abst
 
     /**
      * This method binds the submitted request value to the Field's value.
+     * <p/>
+     * <b>Please note:</b> while it is possible to explicitly bind the field
+     * value by invoking this method directly, it is recommended to use the
+     * "<tt>bind</tt>" utility methods in {@link org.apache.click.util.ClickUtils}
+     * instead. See {@link org.apache.click.util.ClickUtils#bind(org.apache.click.control.Field)}
+     * for more details.
      */
     public void bindRequestValue() {
         setValue(getRequestValue());
@@ -1031,7 +1048,8 @@ public abstract class Field extends Abst
      * <p/>
      * This method will bind the Field request parameter value to the field,
      * validate the submission and invoke its callback listener if defined.
-     * The code of this method is provided below:
+     * <p/>
+     * Below is a typical onProcess implementation:
      *
      * <pre class="codeJava">
      * <span class="kw">public boolean</span> onProcess() {
@@ -1049,6 +1067,19 @@ public abstract class Field extends Abst
      * @return true to continue Page event processing or false otherwise
      */
     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;
+            }
+        }
+
         bindRequestValue();
 
         if (getValidate()) {

Modified: click/trunk/click/framework/src/org/apache/click/control/Radio.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Radio.java?rev=925555&r1=925554&r2=925555&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/Radio.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/Radio.java Sat Mar 20 06:14:11
2010
@@ -18,6 +18,7 @@
  */
 package org.apache.click.control;
 
+import org.apache.click.Context;
 import org.apache.click.util.ClickUtils;
 import org.apache.click.util.HtmlStringBuffer;
 
@@ -310,7 +311,21 @@ public class Radio extends Field {
      *
      * @return true to continue Page event processing or 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;
+            }
+        }
+
         bindRequestValue();
 
         if (isChecked()) {

Modified: click/trunk/click/framework/src/org/apache/click/control/RadioGroup.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/RadioGroup.java?rev=925555&r1=925554&r2=925555&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/RadioGroup.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/RadioGroup.java Sat Mar 20 06:14:11
2010
@@ -25,6 +25,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import org.apache.click.Context;
 
 import org.apache.click.util.HtmlStringBuffer;
 import org.apache.click.util.PropertyUtils;
@@ -114,7 +115,7 @@ public class RadioGroup extends Field {
         + "   '}'\n"
         + "'}'\n";
 
-    // ----------------------------------------------------- Instance Variables
+    // Instance Variables -----------------------------------------------------
 
     /** The list of Radio controls. */
     protected List radioList;
@@ -126,7 +127,7 @@ public class RadioGroup extends Field {
      */
     protected boolean isVerticalLayout = true;
 
-    // ----------------------------------------------------------- Constructors
+    // Constructors -----------------------------------------------------------
 
     /**
      * Create a RadioGroup with the given name.
@@ -179,7 +180,7 @@ public class RadioGroup extends Field {
         super();
     }
 
-    // ------------------------------------------------------ Public Attributes
+    // Public Attributes ------------------------------------------------------
 
     /**
      * Add the given radio to the radio group. When the radio is added to the
@@ -306,6 +307,7 @@ public class RadioGroup extends Field {
      *
      * @return the RadioGroup focus JavaScript
      */
+    @Override
     public String getFocusJavaScript() {
         String id = "";
 
@@ -327,6 +329,7 @@ public class RadioGroup extends Field {
      *
      * @param form Field's parent <tt>Form</tt>
      */
+    @Override
     public void setForm(Form form) {
         super.setForm(form);
         if (hasRadios()) {
@@ -381,6 +384,7 @@ public class RadioGroup extends Field {
      *
      * @return the field JavaScript client side validation function
      */
+    @Override
     public String getValidationJavaScript() {
         Object[] args = new Object[5];
         args[0] = getId();
@@ -398,11 +402,12 @@ public class RadioGroup extends Field {
         return MessageFormat.format(VALIDATE_RADIOGROUP_FUNCTION, args);
     }
 
-    // --------------------------------------------------------- Public Methods
+    // Public Methods ---------------------------------------------------------
 
     /**
      * @see org.apache.click.Control#onInit()
      */
+    @Override
     public void onInit() {
         super.onInit();
         for (int i = 0, size = getRadioList().size(); i < size; i++) {
@@ -419,7 +424,21 @@ public class RadioGroup extends Field {
      *
      * @return true to continue Page event processing or 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;
+            }
+        }
+
         bindRequestValue();
 
         boolean continueProcessing = true;
@@ -442,6 +461,7 @@ public class RadioGroup extends Field {
     /**
      * @see org.apache.click.Control#onDestroy()
      */
+    @Override
     public void onDestroy() {
         for (int i = 0, size = getRadioList().size(); i < size; i++) {
             Radio radio = (Radio) getRadioList().get(i);
@@ -458,6 +478,7 @@ public class RadioGroup extends Field {
      *
      * @return the estimated rendered control size in characters
      */
+    @Override
     public int getControlSizeEst() {
         return getRadioList().size() * 30;
     }
@@ -469,6 +490,7 @@ public class RadioGroup extends Field {
      *
      * @param buffer the specified buffer to render the control's output to
      */
+    @Override
     public void render(HtmlStringBuffer buffer) {
         String value = getValue();
 
@@ -507,6 +529,7 @@ public class RadioGroup extends Field {
      *
      * @return the HTML rendered RadioGroup string
      */
+    @Override
     public String toString() {
         HtmlStringBuffer buffer = new HtmlStringBuffer(getControlSizeEst());
         render(buffer);
@@ -524,6 +547,7 @@ public class RadioGroup extends Field {
      * <li>select-error</li>
      * </ul></blockquote>
      */
+    @Override
     public void validate() {
         setError(null);
 

Modified: click/trunk/click/framework/src/org/apache/click/control/Submit.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Submit.java?rev=925555&r1=925554&r2=925555&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/Submit.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/Submit.java Sat Mar 20 06:14:11
2010
@@ -18,6 +18,7 @@
  */
 package org.apache.click.control;
 
+import org.apache.click.Context;
 import org.apache.commons.lang.StringUtils;
 
 /**
@@ -203,6 +204,19 @@ public class Submit extends Button {
      */
     @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;
+            }
+        }
+
         bindRequestValue();
 
         if (isClicked()) {

Modified: click/trunk/click/framework/src/org/apache/click/util/ContainerUtils.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/util/ContainerUtils.java?rev=925555&r1=925554&r2=925555&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/util/ContainerUtils.java (original)
+++ click/trunk/click/framework/src/org/apache/click/util/ContainerUtils.java Sat Mar 20 06:14:11
2010
@@ -133,6 +133,12 @@ public class ContainerUtils {
 
         for (Field field : fieldList) {
 
+            // Ignore disabled field as their values are not submitted in HTML
+            // forms
+            if (field.isDisabled()) {
+                continue;
+            }
+
             if (!hasMatchingProperty(field, properties)) {
                 continue;
             }



Mime
View raw message