Author: niallp
Date: Tue Apr  5 23:37:00 2005
New Revision: 160261

URL: http://svn.apache.org/viewcvs?view=rev&rev=160261
Log:
Bug 21603 Automatic readonly/disabled settings in struts-html reported by Shai 
Berger.

Modified:
    struts/el/trunk/doc/userGuide/struts-html-el.xml
    struts/el/trunk/src/share/org/apache/strutsel/taglib/html/ELFormTag.java
    
struts/el/trunk/src/share/org/apache/strutsel/taglib/html/ELFormTagBeanInfo.java
    struts/taglib/trunk/doc/userGuide/struts-html.xml
    
struts/taglib/trunk/src/java/org/apache/struts/taglib/html/BaseHandlerTag.java
    struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FormTag.java
    struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ImgTag.java
    struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LinkTag.java
    struts/taglib/trunk/src/java/org/apache/struts/taglib/html/PasswordTag.java
    struts/taglib/trunk/src/java/org/apache/struts/taglib/html/TextTag.java
    struts/taglib/trunk/src/java/org/apache/struts/taglib/html/TextareaTag.java

Modified: struts/el/trunk/doc/userGuide/struts-html-el.xml
URL: 
http://svn.apache.org/viewcvs/struts/el/trunk/doc/userGuide/struts-html-el.xml?view=diff&r1=160260&r2=160261
==============================================================================
--- struts/el/trunk/doc/userGuide/struts-html-el.xml (original)
+++ struts/el/trunk/doc/userGuide/struts-html-el.xml Tue Apr  5 23:37:00 2005
@@ -1640,6 +1640,17 @@
         </attribute>
 
         <attribute>
+            <name>disabled</name>
+            <required>false</required>
+            <rtexprvalue>true</rtexprvalue>
+            <info>
+                Set to <code>true</code> if the Form's input fields should be
+                disabled.
+            </info>
+            <since>Struts 1.2.7</since>
+        </attribute>
+
+        <attribute>
             <name>enctype</name>
             <required>false</required>
             <rtexprvalue>true</rtexprvalue>
@@ -1699,6 +1710,17 @@
             <info>
                 JavaScript event handler executed if the form is submitted.
             </info>
+        </attribute>
+
+        <attribute>
+            <name>readonly</name>
+            <required>false</required>
+            <rtexprvalue>true</rtexprvalue>
+            <info>
+                Set to <code>true</code> if the Form's input fields should be
+                read only.
+            </info>
+            <since>Struts 1.2.7</since>
         </attribute>
 
                <attribute>

Modified: 
struts/el/trunk/src/share/org/apache/strutsel/taglib/html/ELFormTag.java
URL: 
http://svn.apache.org/viewcvs/struts/el/trunk/src/share/org/apache/strutsel/taglib/html/ELFormTag.java?view=diff&r1=160260&r2=160261
==============================================================================
--- struts/el/trunk/src/share/org/apache/strutsel/taglib/html/ELFormTag.java 
(original)
+++ struts/el/trunk/src/share/org/apache/strutsel/taglib/html/ELFormTag.java 
Tue Apr  5 23:37:00 2005
@@ -42,6 +42,11 @@
      */
     private String actionExpr;
     /**
+     * Instance variable mapped to "disabled" tag attribute.
+     * (Mapping set in associated BeanInfo class.)
+     */
+    private String disabledExpr;
+    /**
      * Instance variable mapped to "enctype" tag attribute.
      * (Mapping set in associated BeanInfo class.)
      */
@@ -72,6 +77,11 @@
      */
     private String onsubmitExpr;
     /**
+     * Instance variable mapped to "readonly" tag attribute.
+     * (Mapping set in associated BeanInfo class.)
+     */
+    private String readonlyExpr;
+    /**
      * Instance variable mapped to "scriptLanguage" tag attribute.
      * (Mapping set in associated BeanInfo class.)
      */
@@ -108,6 +118,11 @@
      */
     public String getActionExpr() { return (actionExpr); }
     /**
+     * Getter method for "disabled" tag attribute.
+     * (Mapping set in associated BeanInfo class.)
+     */
+    public String getDisabledExpr() { return (disabledExpr); }
+    /**
      * Getter method for "enctype" tag attribute.
      * (Mapping set in associated BeanInfo class.)
      */
@@ -138,6 +153,11 @@
      */
     public String getOnsubmitExpr() { return (onsubmitExpr); }
     /**
+     * Getter method for "readonly" tag attribute.
+     * (Mapping set in associated BeanInfo class.)
+     */
+    public String getReadonlyExpr() { return (readonlyExpr); }
+    /**
      * Getter method for "scriptLanguage" tag attribute.
      * (Mapping set in associated BeanInfo class.)
      */
@@ -174,6 +194,11 @@
      */
     public void setActionExpr(String actionExpr) { this.actionExpr = 
actionExpr; }
     /**
+     * Setter method for "disabled" tag attribute.
+     * (Mapping set in associated BeanInfo class.)
+     */
+    public void setDisabledExpr(String disabledExpr) { this.disabledExpr = 
disabledExpr; }
+    /**
      * Setter method for "enctype" tag attribute.
      * (Mapping set in associated BeanInfo class.)
      */
@@ -204,6 +229,11 @@
      */
     public void setOnsubmitExpr(String onsubmitExpr) { this.onsubmitExpr = 
onsubmitExpr; }
     /**
+     * Setter method for "readonly" tag attribute.
+     * (Mapping set in associated BeanInfo class.)
+     */
+    public void setReadonlyExpr(String readonlyExpr) { this.readonlyExpr = 
readonlyExpr; }
+    /**
      * Setter method for "scriptLanguage" tag attribute.
      * (Mapping set in associated BeanInfo class.)
      */
@@ -241,12 +271,14 @@
     {
         super.release();
         setActionExpr(null);
+        setDisabledExpr(null);
         setEnctypeExpr(null);
         setFocusExpr(null);
         setFocusIndexExpr(null);
         setMethodExpr(null);
         setOnresetExpr(null);
         setOnsubmitExpr(null);
+        setReadonlyExpr(null);
         setScriptLanguageExpr(null);
         setStyleExpr(null);
         setStyleClassExpr(null);
@@ -279,6 +311,10 @@
                                             this, pageContext)) != null)
             setAction(string);
 
+        if ((bool = EvalHelper.evalBoolean("disabled", getDisabledExpr(),
+                                           this, pageContext)) != null)
+            setDisabled(bool.booleanValue());
+
         if ((string = EvalHelper.evalString("enctype", getEnctypeExpr(),
                                             this, pageContext)) != null)
             setEnctype(string);
@@ -302,6 +338,10 @@
         if ((string = EvalHelper.evalString("onsubmit", getOnsubmitExpr(),
                                             this, pageContext)) != null)
             setOnsubmit(string);
+
+        if ((bool = EvalHelper.evalBoolean("readonly", getReadonlyExpr(),
+                                           this, pageContext)) != null)
+            setReadonly(bool.booleanValue());
 
        if ((bool = EvalHelper.evalBoolean("scriptLanguage", 
getScriptLanguageExpr(),
                                           this, pageContext)) != null)

Modified: 
struts/el/trunk/src/share/org/apache/strutsel/taglib/html/ELFormTagBeanInfo.java
URL: 
http://svn.apache.org/viewcvs/struts/el/trunk/src/share/org/apache/strutsel/taglib/html/ELFormTagBeanInfo.java?view=diff&r1=160260&r2=160261
==============================================================================
--- 
struts/el/trunk/src/share/org/apache/strutsel/taglib/html/ELFormTagBeanInfo.java
 (original)
+++ 
struts/el/trunk/src/share/org/apache/strutsel/taglib/html/ELFormTagBeanInfo.java
 Tue Apr  5 23:37:00 2005
@@ -40,6 +40,10 @@
                                                 null, "setActionExpr"));
         } catch (IntrospectionException ex) {}
         try {
+            proplist.add(new PropertyDescriptor("disabled", ELTextTag.class,
+                                                null, "setDisabledExpr"));
+        } catch (IntrospectionException ex) {}
+        try {
             proplist.add(new PropertyDescriptor("enctype", ELFormTag.class,
                                                 null, "setEnctypeExpr"));
         } catch (IntrospectionException ex) {}
@@ -66,6 +70,10 @@
         try {
             proplist.add(new PropertyDescriptor("onsubmit", ELFormTag.class,
                                                 null, "setOnsubmitExpr"));
+        } catch (IntrospectionException ex) {}
+        try {
+            proplist.add(new PropertyDescriptor("readonly", ELTextTag.class,
+                                                null, "setReadonlyExpr"));
         } catch (IntrospectionException ex) {}
         try {
             proplist.add(new PropertyDescriptor("scope", ELFormTag.class,

Modified: struts/taglib/trunk/doc/userGuide/struts-html.xml
URL: 
http://svn.apache.org/viewcvs/struts/taglib/trunk/doc/userGuide/struts-html.xml?view=diff&r1=160260&r2=160261
==============================================================================
--- struts/taglib/trunk/doc/userGuide/struts-html.xml (original)
+++ struts/taglib/trunk/doc/userGuide/struts-html.xml Tue Apr  5 23:37:00 2005
@@ -1640,6 +1640,17 @@
         </attribute>
 
         <attribute>
+            <name>disabled</name>
+            <required>false</required>
+            <rtexprvalue>true</rtexprvalue>
+            <info>
+                Set to <code>true</code> if the Form's input fields should be
+                disabled.
+            </info>
+            <since>Struts 1.2.7</since>
+        </attribute>
+
+        <attribute>
             <name>enctype</name>
             <required>false</required>
             <rtexprvalue>true</rtexprvalue>
@@ -1699,6 +1710,17 @@
             <info>
                 JavaScript event handler executed if the form is submitted.
             </info>
+        </attribute>
+
+        <attribute>
+            <name>readonly</name>
+            <required>false</required>
+            <rtexprvalue>true</rtexprvalue>
+            <info>
+                Set to <code>true</code> if the Form's input fields should be
+                read only.
+            </info>
+            <since>Struts 1.2.7</since>
         </attribute>
 
                <attribute>

Modified: 
struts/taglib/trunk/src/java/org/apache/struts/taglib/html/BaseHandlerTag.java
URL: 
http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/BaseHandlerTag.java?view=diff&r1=160260&r2=160261
==============================================================================
--- 
struts/taglib/trunk/src/java/org/apache/struts/taglib/html/BaseHandlerTag.java 
(original)
+++ 
struts/taglib/trunk/src/java/org/apache/struts/taglib/html/BaseHandlerTag.java 
Tue Apr  5 23:37:00 2005
@@ -132,9 +132,22 @@
     /** Component is disabled. */
     private boolean disabled = false;
 
+    /** Indicates whether 'disabled' is a valid attribute */
+    protected boolean doDisabled = true;
+
     /** Component is readonly. */
     private boolean readonly = false;
 
+    /** 
+     * <p>Indicates whether 'readonly' is a valid attribute.</p>
+     *
+     * <p>According to the HTML 4.0 Specification &lt;readonly&gt;
+     *    is valid for &lt;input type="text"&gt;, &lt;input type="password"&gt;
+     *    and &lt;textarea"&gt; elements. Therefore, except for those tags this
+     *    value is set to <code>false</code>.</p>
+     */
+    protected boolean doReadonly = false;
+
     // CSS Style Support
 
     /** Style attribute associated with component. */
@@ -844,12 +857,27 @@
         prepareAttribute(handlers, "onblur", getOnblur());
         prepareAttribute(handlers, "onfocus", getOnfocus());
 
-        if (getDisabled()) {
-            handlers.append(" disabled=\"disabled\"");
+        // Get the parent FormTag (if necessary)
+        FormTag formTag = null;
+        if ((doDisabled && !getDisabled()) ||
+            (doReadonly && !getReadonly())) {
+            formTag = (FormTag)findAncestorWithClass(this, FormTag.class);
         }
 
-        if (getReadonly()) {
-            handlers.append(" readonly=\"readonly\"");
+        // Format Disabled
+        if (doDisabled) {
+            boolean formDisabled = formTag == null ? false : 
formTag.isDisabled();
+            if (formDisabled || getDisabled()) {
+                handlers.append(" disabled=\"disabled\"");
+            }
+        }
+
+        // Format Read Only
+        if (doReadonly) {
+            boolean formReadOnly = formTag == null ? false : 
formTag.isReadonly();
+            if (formReadOnly || getReadonly()) {
+                handlers.append(" readonly=\"readonly\"");
+            }
         }
 
     }

Modified: 
struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FormTag.java
URL: 
http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FormTag.java?view=diff&r1=160260&r2=160261
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FormTag.java 
(original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/FormTag.java Tue 
Apr  5 23:37:00 2005
@@ -169,6 +169,12 @@
      */
     protected String acceptCharset = null;
 
+    /** Controls whether child controls should be 'disabled'. */
+    private boolean disabled = false;
+
+    /** Controls whether child controls should be 'readonly'. */
+    protected boolean readonly = false;
+
     // ------------------------------------------------------------- Properties
 
     /**
@@ -403,6 +409,26 @@
 
     }
 
+    /** Sets the disabled event handler. */
+    public void setDisabled(boolean disabled) {
+        this.disabled = disabled;
+    }
+
+    /** Returns the disabled event handler. */
+    public boolean isDisabled() {
+        return disabled;
+    }
+
+    /** Sets the readonly event handler. */
+    public void setReadonly(boolean readonly) {
+        this.readonly = readonly;
+    }
+
+    /** Returns the readonly event handler. */
+    public boolean isReadonly() {
+        return readonly;
+    }
+
 
     // --------------------------------------------------------- Public Methods
 
@@ -680,12 +706,14 @@
         action = null;
         moduleConfig = null;
         enctype = null;
+        disabled = false;
         focus = null;
         focusIndex = null;
         mapping = null;
         method = null;
         onreset = null;
         onsubmit = null;
+        readonly = false;
         servlet = null;
         style = null;
         styleClass = null;

Modified: struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ImgTag.java
URL: 
http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ImgTag.java?view=diff&r1=160260&r2=160261
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ImgTag.java 
(original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/ImgTag.java Tue 
Apr  5 23:37:00 2005
@@ -44,6 +44,13 @@
 
 public class ImgTag extends BaseHandlerTag {
 
+    // ----------------------------------------------------- Constructor
+
+    public ImgTag() {
+        super();
+        doDisabled = false;
+    }
+
     // ------------------------------------------------------------- Properties
 
      /**

Modified: 
struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LinkTag.java
URL: 
http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LinkTag.java?view=diff&r1=160260&r2=160261
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LinkTag.java 
(original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/LinkTag.java Tue 
Apr  5 23:37:00 2005
@@ -44,6 +44,13 @@
      */
     protected String text = null;
 
+    // ----------------------------------------------------- Constructor
+
+    public LinkTag() {
+        super();
+        doDisabled = false;
+    }
+
 
     // ------------------------------------------------------------- Properties
 

Modified: 
struts/taglib/trunk/src/java/org/apache/struts/taglib/html/PasswordTag.java
URL: 
http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/PasswordTag.java?view=diff&r1=160260&r2=160261
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/PasswordTag.java 
(original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/PasswordTag.java 
Tue Apr  5 23:37:00 2005
@@ -31,6 +31,7 @@
     public PasswordTag() {
         super();
         this.type = "password";
+        doReadonly = true;
     }
 
 }

Modified: 
struts/taglib/trunk/src/java/org/apache/struts/taglib/html/TextTag.java
URL: 
http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/TextTag.java?view=diff&r1=160260&r2=160261
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/TextTag.java 
(original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/TextTag.java Tue 
Apr  5 23:37:00 2005
@@ -34,8 +34,9 @@
      */
     public TextTag() {
 
-          super();
-          this.type = "text";
+         super();
+         this.type = "text";
+         doReadonly = true;
 
     }
 

Modified: 
struts/taglib/trunk/src/java/org/apache/struts/taglib/html/TextareaTag.java
URL: 
http://svn.apache.org/viewcvs/struts/taglib/trunk/src/java/org/apache/struts/taglib/html/TextareaTag.java?view=diff&r1=160260&r2=160261
==============================================================================
--- struts/taglib/trunk/src/java/org/apache/struts/taglib/html/TextareaTag.java 
(original)
+++ struts/taglib/trunk/src/java/org/apache/struts/taglib/html/TextareaTag.java 
Tue Apr  5 23:37:00 2005
@@ -30,6 +30,13 @@
 public class TextareaTag extends BaseInputTag {
 
 
+    // ----------------------------------------------------- Constructor
+
+    public TextareaTag () {
+        super();
+        doReadonly = true;
+    }
+
     // --------------------------------------------------------- Public Methods
 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to