Author: karlvr Date: Sat Apr 21 23:19:13 2007 New Revision: 531148 URL: http://svn.apache.org/viewvc?view=rev&rev=531148 Log: Array support changed to be automatic rather than specified per tag Array support removed for checkboxes, radio buttons and select boxes in !multiple mode bug #12189: Checkbox can now detect whether to use defaults or not in a smarter manner, rather than just checking if the request is empty Example pages added to demonstrate new functionality BaseTag and BaseInputTag refactored so that BaseTag only contains generic HTML elements
Added: jakarta/taglibs/proper/input/trunk/examples/web/array.jsp jakarta/taglibs/proper/input/trunk/examples/web/array2.jsp jakarta/taglibs/proper/input/trunk/examples/web/checkboxes.jsp jakarta/taglibs/proper/input/trunk/examples/web/form2.jsp Modified: jakarta/taglibs/proper/input/trunk/examples/web/form.jsp jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/BaseInputTag.java jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/BaseTag.java jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Checkbox.java jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Form.java jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Hidden.java jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Password.java jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Radio.java jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Select.java jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Text.java jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/TextArea.java jakarta/taglibs/proper/input/trunk/xml/input.xml Added: jakarta/taglibs/proper/input/trunk/examples/web/array.jsp URL: http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/examples/web/array.jsp?view=auto&rev=531148 ============================================================================== --- jakarta/taglibs/proper/input/trunk/examples/web/array.jsp (added) +++ jakarta/taglibs/proper/input/trunk/examples/web/array.jsp Sat Apr 21 23:19:13 2007 @@ -0,0 +1,52 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<!-- + Copyright (c) 2007 The Apache Software Foundation. All rights reserved. + Author: Karl von Randow ([EMAIL PROTECTED]) + + Demonstrates form elements as part of an array + +--> + +<body bgcolor="#eeeeee"> +<%@ taglib uri="http://jakarta.apache.org/taglibs/input-1.2" prefix="input" %> + +<input:form> +<p>When there are multiple input tags on the page with the same name they become an array +of parameter values when submitted. See request.getParameterValues(String name). The input +tag library now supports repopulating those form fields correctly.</p> + +<p> +Enter the names of up to 3 friends:<br /> +<input:text name="friend" default="Karl" /><br /> +<input:text name="friend" default="Shawn" /><br /> +<input:text name="friend" default="Lance" /><br /> +<br /> +Previously only the first field would be repopulated, as all three fields have the same name. +Now the fields are repopulated correctly. The only requirement is that you use an <input:form> +tag rather than the plain <form> tag. +<br /> + +<input type="submit" /> + +</p> +</input:form> + + +<form> +<p> +This is the sample example as above except without the <input:form> tag so it reverts to +the original behaviour.<br /><br /> +Enter the names of up to 3 friends:<br /> +<input:text name="friend" default="Karl" /><br /> +<input:text name="friend" default="Shawn" /><br /> +<input:text name="friend" default="Lance" /><br /> +<br /> + +<input type="submit" /> + +</p> +</form> + +</body> +</html> Added: jakarta/taglibs/proper/input/trunk/examples/web/array2.jsp URL: http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/examples/web/array2.jsp?view=auto&rev=531148 ============================================================================== --- jakarta/taglibs/proper/input/trunk/examples/web/array2.jsp (added) +++ jakarta/taglibs/proper/input/trunk/examples/web/array2.jsp Sat Apr 21 23:19:13 2007 @@ -0,0 +1,45 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<!-- + Copyright (c) 2007 The Apache Software Foundation. All rights reserved. + Author: Karl von Randow ([EMAIL PROTECTED]) + + Demonstrates form elements as part of an array + +--> + +<body bgcolor="#eeeeee"> +<%@ taglib uri="http://jakarta.apache.org/taglibs/input-1.2" prefix="input" %> +<[EMAIL PROTECTED] import="java.util.ArrayList" %> +<input:form> +<p> +Array behaviour works with textareas as well. Enter three reasons:<br /> +<input:textarea name="reason" cols="40" rows="2" /><br /> +<input:textarea name="reason" cols="40" rows="3">I have some default text in the body of the tag</input:textarea><br /> +<input:textarea name="reason" cols="40" rows="2" default="My default text is an attribute"/><br /> +<br /> + +It also works with select boxes. Choose your three favourite animals:<br /> +<% +ArrayList things = new ArrayList(); +things.add("cats"); +things.add("dogs"); +things.add("rabbits"); +things.add("horses"); +things.add("donkeys"); +%> +<input:select name="fav" optionLabels="<%=things %>" /> +<input:select name="fav" optionLabels="<%=things %>" /> +<input:select name="fav" optionLabels="<%=things %>" /><br /> +<br /> +Note that select boxes with multiple=true do not participate in the array scheme. So this +select will show all of the selections made for "fav".<br /> +<input:select name="fav" optionLabels="<%=things %>" size="5" multiple="true" /><br /> + +<input type="submit" /> + +</p> +</input:form> + +</body> +</html> Added: jakarta/taglibs/proper/input/trunk/examples/web/checkboxes.jsp URL: http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/examples/web/checkboxes.jsp?view=auto&rev=531148 ============================================================================== --- jakarta/taglibs/proper/input/trunk/examples/web/checkboxes.jsp (added) +++ jakarta/taglibs/proper/input/trunk/examples/web/checkboxes.jsp Sat Apr 21 23:19:13 2007 @@ -0,0 +1,88 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<!-- + Copyright (c) 2007 The Apache Software Foundation. All rights reserved. + Author: Karl von Randow ([EMAIL PROTECTED]) + + Demonstrates the behaviour of checkboxes + +--> + +<body bgcolor="#eeeeee"> +<%@ taglib uri="http://jakarta.apache.org/taglibs/input-1.2" prefix="input" %> + +<p> +Checkboxes are slightly troublesome elements as when they are unchecked they submit no value at all. +So it is difficult to detect whether we are seeing a form for the first time, and therefore should +use the default values for a checkbox; or whether we are repopulating a form and the absense of a +value in the request for a given checkbox means it was unchecked. +</p> +<p> +The input tag library previously decided whether to use defaults or not based on whether there +were any request parameters at all. If there were any request parameters then it was assumed we +are repopulating the form and therefore checkbox default values aren't used. +</p> +<p> +As of version 1.2 the input tag library can detect if there are parameters in the request matching +other tags in the form. If there aren't then it knows that the form isn't being repopulated, even +though there may be other parameters in the request. Note that it can only be sure if there are +non-checkbox fields in the form, so if there are only checkboxes then it reverts back to the original +behaviour as above. +</p> +<p> +To make use of this new behaviour you must use an <input:form> +tag rather than the plain <form> tag. +</p> + +<input:form> +<p>This form has a text field and checkboxes, so it can correctly detect whether to use defaults. +You can verify that by <a href="?thisNameIsntUsedInTheForm=true">viewing the page with a query parameter that doesn't match any field in +the form</a>, and see that even though there are parameters in the request the checkboxes can still see +that they should use their default values.</p> + +<p> +What is your name?:<br /> +<input:text name="name" /> +</p> +<% +String[] defaults = new String[] { "rabbits", "donkeys" }; +%> +<p> +Which animals do you like?:<br /> +<input:checkbox name="animals" value="cats" defaults="<%=defaults %>" />Cats<br /> +<input:checkbox name="animals" value="dogs" defaults="<%=defaults %>" />Dogs<br /> +<input:checkbox name="animals" value="rabbits" defaults="<%=defaults %>" />Rabbits<br /> +<input:checkbox name="animals" value="horses" defaults="<%=defaults %>" />Horses<br /> +<input:checkbox name="animals" value="donkeys" defaults="<%=defaults %>" />Donkeys<br /> +<br /> + +<input type="submit" /> + +</p> +</input:form> + +<input:form> +<p>Compare the above form with this form where there are only checkboxes. The checkboxes +can't accurately detect whether they should use their default values or not. +You can see this when the defaults aren't used, contrary to the example above, when +<a href="?thisNameIsntUsedInTheForm=true">viewing the page with a query parameter that doesn't match any field in +the form</a>. +<p> +<% +String[] defaults = new String[] { "rabbits", "donkeys" }; +%> +Which animals do you like?:<br /> +<input:checkbox name="animals" value="cats" defaults="<%=defaults %>" />Cats<br /> +<input:checkbox name="animals" value="dogs" defaults="<%=defaults %>" />Dogs<br /> +<input:checkbox name="animals" value="rabbits" defaults="<%=defaults %>" />Rabbits<br /> +<input:checkbox name="animals" value="horses" defaults="<%=defaults %>" />Horses<br /> +<input:checkbox name="animals" value="donkeys" defaults="<%=defaults %>" />Donkeys<br /> +<br /> + +<input type="submit" /> + +</p> +</input:form> + +</body> +</html> Modified: jakarta/taglibs/proper/input/trunk/examples/web/form.jsp URL: http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/examples/web/form.jsp?view=diff&rev=531148&r1=531147&r2=531148 ============================================================================== --- jakarta/taglibs/proper/input/trunk/examples/web/form.jsp (original) +++ jakarta/taglibs/proper/input/trunk/examples/web/form.jsp Sat Apr 21 23:19:13 2007 @@ -9,12 +9,13 @@ GETting back to itself, which is convenient since you can see the values that the browser sends back as well as tamper with them and watch your changes get reflected on the form. + + NOTE: See form2.jsp for new alternatives to the examples below. --> <body bgcolor="#eeeeee"> <%@ taglib uri="http://jakarta.apache.org/taglibs/input-1.2" prefix="input" %> -<p> <% java.util.Hashtable h = new java.util.Hashtable(); Added: jakarta/taglibs/proper/input/trunk/examples/web/form2.jsp URL: http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/examples/web/form2.jsp?view=auto&rev=531148 ============================================================================== --- jakarta/taglibs/proper/input/trunk/examples/web/form2.jsp (added) +++ jakarta/taglibs/proper/input/trunk/examples/web/form2.jsp Sat Apr 21 23:19:13 2007 @@ -0,0 +1,90 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<!-- + Copyright (c) 2000 The Apache Software Foundation. All rights reserved. + Author: Karl von Randow ([EMAIL PROTECTED]) + + This is a simple test of the "input" taglib. The <form> defaults to + GETting back to itself, which is convenient since you can see the + values that the browser sends back as well as tamper with them and + watch your changes get reflected on the form. + + This example shows the new alternatives to the examples in form.jsp + +--> +<head> + <style type="text/css"> + input.textbox { + background-color: magenta; + } + </style> +</head> +<body bgcolor="#eeeeee"> +<%@ taglib uri="http://jakarta.apache.org/taglibs/input-1.2" prefix="input" %> + +<input:form> +<p> +Username: <input:text name="username" default="shawn" maxlength="10" onclick="this.select()" /><br /> +Full Name: <input:text name="fullname" default="Shawn Bayern" className="textbox" /> + + +<br /> +<br /> + +Statement of purpose: + <input:textarea + name="purpose" + default="none at this time" /> + +<br /> +<br /> + +Choose one: + +<br /> +<br /> + +<input:select name="choice" default="2" size="3" multiple="true"> + <input:option value="1">one</input:option> + <input:option value="2">two</input:option> + <input:option value="3">three</input:option> +</input:select> + +<br /> +<br /> + +<!-- the syntax for "defaults" for radio buttons and checkboxes seems + more sensible when the different buttons or boxes are constructed + automatically. it's still less tedious that having logic that + outputs "checked" on each line, though. + --> + +Favorite letter?   +<input:radio name="radio" value="a" default="a"/>a +<input:radio name="radio" value="b" default="a"/>b +<input:radio name="radio" value="c" default="a"/>c +<input:radio name="radio" value="d" default="a"/>d + +<br /> +<br /> + +<% +String[] defaults = new String[2]; +defaults[0] = "2"; +defaults[1] = "5"; +%> + +Numbers you don't mind:   +<input:checkbox name="checkbox" value="1" defaults="<%= defaults %>"/>1 +<input:checkbox name="checkbox" value="2" defaults="<%= defaults %>"/>2 +<input:checkbox name="checkbox" value="3" defaults="<%= defaults %>"/>3 +<input:checkbox name="checkbox" value="4" defaults="<%= defaults %>"/>4 +<input:checkbox name="checkbox" value="5" defaults="<%= defaults %>"/>5 + +<input type="submit" /> + +</p> +</input:form> + +</body> +</html> Modified: jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/BaseInputTag.java URL: http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/BaseInputTag.java?view=diff&rev=531148&r1=531147&r2=531148 ============================================================================== --- jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/BaseInputTag.java (original) +++ jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/BaseInputTag.java Sat Apr 21 23:19:13 2007 @@ -17,6 +17,31 @@ private String defaultValue; private String[] defaultValueArray; + + /** + * input / textarea common + */ + private boolean disabled, readonly; + + private String onselect, onchange; + + /* + * input tag + */ + private String size, src, alt, usemap, accept; + + private int maxlength; + + private boolean maxlengthSupplied; + + /** + * Custom attributes + */ + private Map attributes; // attributes of the <select> element + + private String attributesText; // attributes of the <input> element as text + + private Form form; protected void init() { super.init(); @@ -24,12 +49,41 @@ defaultValue = null; defaultValueArray = null; beanId = null; + + disabled = false; + readonly = false; + + onselect = null; + onchange = null; + + size = null; + maxlength = 0; + maxlengthSupplied = false; + src = null; + alt = null; + usemap = null; + + accept = null; + + attributes = null; + attributesText = null; + + form = null; } protected void validate() throws JspTagException { if (name == null || name.equals("")) { throw new JspTagException("Invalid null or empty 'name'"); } + + form = Util.findFormTag(this); + if (form != null) { + form.visitTag(this); + } + } + + protected Form getForm() { + return form; } public void printAttributes(JspWriter out) throws JspTagException, IOException { @@ -37,10 +91,39 @@ printAttribute(out, "name", name); } super.printAttributes(out); + + printAttribute(out, "size", size); + if (maxlengthSupplied) { + printAttribute(out, "maxlength", new Integer(maxlength)); + } + printAttribute(out, "src", src); + printAttribute(out, "alt", alt); + printAttribute(out, "usemap", usemap); + + printAttribute(out, "accept", accept); + + printAttribute(out, "disabled", disabled); + printAttribute(out, "readonly", readonly); + + printAttribute(out, "onselect", onselect); + printAttribute(out, "onchange", onchange); + + /* Custom attributes */ + Util.printAttributes(out, attributes); + if (attributesText != null) { + out.print(" " + attributesText); + } } - - protected String findValue() throws JspTagException { + /** + * Find the value to use for this input tag. Looks in a bean, or in the request or at + * default values in that order. Automatically detects if this input tag has the same + * name as another input tag in the form and populates as if part of an array of values. + * @param supportsArrayMode TODO + * @return + * @throws JspTagException + */ + protected String findValue(boolean supportsArrayMode) throws JspTagException { /* Get beanId from the form if it isn't set here */ String beanId = this.beanId; if (beanId == null) { @@ -48,29 +131,21 @@ } ServletRequest request = pageContext.getRequest(); - - if (array) { - Form form = Util.findFormTag(this); - if (form != null) { - int index = form.nextIndex(name); - if (beanId != null && beanId.length() == 0) { - /* An empty beanId means use an imaginary empty bean */ - return null; - } else if (beanId != null && pageContext.findAttribute(beanId) != null) { - /* Use the property values from the bean if the bean exists */ - return Util.beanPropertyValue(pageContext.findAttribute(beanId), name, index); - } else if (request.getParameter(name) != null) { - String[] values = request.getParameterValues(name); - if (values != null && values.length > index) { - return values[index]; - } else { - return null; - } + + if (form != null && supportsArrayMode) { + int index = form.nextIndex(name); + if (beanId != null && beanId.length() > 0 && pageContext.findAttribute(beanId) != null) { + /* Use the property values from the bean if the bean exists */ + return Util.beanPropertyValue(pageContext.findAttribute(beanId), name, index); + } else if (request.getParameter(name) != null) { + String[] values = request.getParameterValues(name); + if (values != null && values.length > index) { + return values[index]; } else { - return findDefaultValue(); + return null; } } else { - throw new JspTagException("Input tag in array used outside of a form tag"); + return findDefaultValue(); } } else { if (beanId != null && beanId.length() == 0) { @@ -97,6 +172,13 @@ } } + /** + * Find the values to use for this input tag. The order to find in is the same as + * for the findValues method. This method returns an array of values. It therefore + * does not support acting as part of an array made up of same-named input tags. + * @return + * @throws JspTagException + */ protected String[] findValues() throws JspTagException { /* Get beanId from the form if it isn't set here */ String beanId = this.beanId; @@ -106,41 +188,16 @@ ServletRequest request = pageContext.getRequest(); - if (array) { - Form form = Util.findFormTag(this); - if (form != null) { - int index = form.nextIndex(name); - if (beanId != null && beanId.length() == 0) { - /* An empty beanId means use an imaginary empty bean */ - return null; - } else if (beanId != null && pageContext.findAttribute(beanId) != null) { - /* Use the property values from the bean */ - return Util.beanPropertyValues(pageContext.findAttribute(beanId), name, index); - } else if (request.getParameter(name) != null) { - String[] values = request.getParameterValues(name); - if (values != null && values.length > index) { - return new String[] { values[index] }; - } else { - return null; - } - } else { - return findDefaultValues(); - } - } else { - throw new JspTagException("Input tag in array used outside of a form tag"); - } + if (beanId != null && beanId.length() == 0) { + /* An empty beanId means use an imaginary empty bean */ + return null; + } else if (beanId != null && pageContext.findAttribute(beanId) != null) { + /* Use the property values from the bean */ + return Util.beanPropertyValues(pageContext.findAttribute(beanId), name); + } else if (request.getParameterValues(name) != null) { + return request.getParameterValues(name); } else { - if (beanId != null && beanId.length() == 0) { - /* An empty beanId means use an imaginary empty bean */ - return null; - } else if (beanId != null && pageContext.findAttribute(beanId) != null) { - /* Use the property values from the bean */ - return Util.beanPropertyValues(pageContext.findAttribute(beanId), name); - } else if (request.getParameterValues(name) != null) { - return request.getParameterValues(name); - } else { - return findDefaultValues(); - } + return findDefaultValues(); } } @@ -210,6 +267,102 @@ defaultValueArray[i++] = it.next().toString(); } } - + + public Map getAttributes() { + return attributes; + } + + public void setAttributes(Map attributes) { + this.attributes = attributes; + } + + public String getAttributesText() { + return attributesText; + } + + public void setAttributesText(String attributesText) { + this.attributesText = attributesText; + } + + public boolean getDisabled() { + return disabled; + } + + public void setDisabled(boolean disabled) { + this.disabled = disabled; + } + + public String getOnchange() { + return onchange; + } + + public void setOnchange(String onchange) { + this.onchange = onchange; + } + + public String getOnselect() { + return onselect; + } + + public void setOnselect(String onselect) { + this.onselect = onselect; + } + + public boolean getReadonly() { + return readonly; + } + + public void setReadonly(boolean readonly) { + this.readonly = readonly; + } + + public String getAccept() { + return accept; + } + + public void setAccept(String accept) { + this.accept = accept; + } + + public String getAlt() { + return alt; + } + + public void setAlt(String alt) { + this.alt = alt; + } + + public int getMaxlength() { + return maxlength; + } + + public void setMaxlength(int maxlength) { + this.maxlength = maxlength; + this.maxlengthSupplied = true; + } + + public String getSize() { + return size; + } + + public void setSize(String size) { + this.size = size; + } + + public String getSrc() { + return src; + } + + public void setSrc(String src) { + this.src = src; + } + + public String getUsemap() { + return usemap; + } + + public void setUsemap(String usemap) { + this.usemap = usemap; + } } Modified: jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/BaseTag.java URL: http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/BaseTag.java?view=diff&rev=531148&r1=531147&r2=531148 ============================================================================== --- jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/BaseTag.java (original) +++ jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/BaseTag.java Sat Apr 21 23:19:13 2007 @@ -16,7 +16,6 @@ package org.apache.taglibs.input; import java.io.IOException; -import java.util.Map; import javax.servlet.jsp.JspTagException; import javax.servlet.jsp.JspWriter; @@ -58,31 +57,6 @@ private Integer tabindex; - /** - * input / textarea common - */ - private boolean disabled, readonly; - - private String onselect, onchange; - - /* - * input tag - */ - private String size, src, alt, usemap, accept; - - private int maxlength; - - private boolean maxlengthSupplied; - - /** - * Custom attributes - */ - private Map attributes; // attributes of the <select> element - - private String attributesText; // attributes of the <input> element as text - - protected boolean array; - public BaseTag() { super(); init(); @@ -117,26 +91,6 @@ tabindex = null; onfocus = null; onblur = null; - - disabled = false; - readonly = false; - - onselect = null; - onchange = null; - - size = null; - maxlength = 0; - maxlengthSupplied = false; - src = null; - alt = null; - usemap = null; - - accept = null; - - attributes = null; - attributesText = null; - - array = false; } public void printAttributes(JspWriter out) throws JspTagException, IOException { @@ -148,22 +102,6 @@ printAttribute(out, "lang", lang); printAttribute(out, "dir", dir); - printAttribute(out, "size", size); - if (maxlengthSupplied) { - printAttribute(out, "maxlength", new Integer(maxlength)); - } - printAttribute(out, "src", src); - printAttribute(out, "alt", alt); - printAttribute(out, "usemap", usemap); - - printAttribute(out, "accept", accept); - - printAttribute(out, "disabled", disabled); - printAttribute(out, "readonly", readonly); - - printAttribute(out, "onselect", onselect); - printAttribute(out, "onchange", onchange); - printAttribute(out, "onclick", onclick); printAttribute(out, "ondblclick", ondblclick); printAttribute(out, "onmousedown", onmousedown); @@ -179,12 +117,6 @@ printAttribute(out, "tabindex", tabindex); printAttribute(out, "onfocus", onfocus); printAttribute(out, "onblur", onblur); - - /* Custom attributes */ - Util.printAttributes(out, attributes); - if (attributesText != null) { - out.print(" " + attributesText); - } } protected void printAttribute(JspWriter out, String name, boolean value) throws IOException { @@ -227,22 +159,6 @@ this.accesskey = accesskey; } - public Map getAttributes() { - return attributes; - } - - public void setAttributes(Map attributes) { - this.attributes = attributes; - } - - public String getAttributesText() { - return attributesText; - } - - public void setAttributesText(String attributesText) { - this.attributesText = attributesText; - } - public String getClassName() { return className; } @@ -393,95 +309,6 @@ public void setTitle(String title) { this.title = title; - } - - public boolean isArray() { - return array; - } - - public void setArray(boolean multiple) { - this.array = multiple; - } - - public boolean getDisabled() { - return disabled; - } - - public void setDisabled(boolean disabled) { - this.disabled = disabled; - } - - public String getOnchange() { - return onchange; - } - - public void setOnchange(String onchange) { - this.onchange = onchange; - } - - public String getOnselect() { - return onselect; - } - - public void setOnselect(String onselect) { - this.onselect = onselect; - } - - public boolean getReadonly() { - return readonly; - } - - public void setReadonly(boolean readonly) { - this.readonly = readonly; - } - - public String getAccept() { - return accept; - } - - public void setAccept(String accept) { - this.accept = accept; - } - - public String getAlt() { - return alt; - } - - public void setAlt(String alt) { - this.alt = alt; - } - - public int getMaxlength() { - return maxlength; - } - - public void setMaxlength(int maxlength) { - this.maxlength = maxlength; - this.maxlengthSupplied = true; - } - - public String getSize() { - return size; - } - - public void setSize(String size) { - this.size = size; - } - - public String getSrc() { - return src; - } - - public void setSrc(String src) { - this.src = src; - } - - public String getUsemap() { - return usemap; - } - - public void setUsemap(String usemap) { - this.usemap = usemap; } } Modified: jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Checkbox.java URL: http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Checkbox.java?view=diff&rev=531148&r1=531147&r2=531148 ============================================================================== --- jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Checkbox.java (original) +++ jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Checkbox.java Sat Apr 21 23:19:13 2007 @@ -73,16 +73,28 @@ } protected String[] findDefaultValues() { - /* Only use default values if the request is completely empty; - * this is different from what we do with the other input - * types, checking "defaults" when there's no value for the specific - * field. This difference is the result of the underlying - * inconsistency between checkboxes and everything else. - */ - if (!pageContext.getRequest().getParameterNames().hasMoreElements()) { - return super.findDefaultValues(); + Form form = getForm(); + if (form != null && form.isRepopulatingReliable()) { + /* Check if other fields in the form have reported that they have been + * repopulated by this request. + */ + if (!form.isRepopulating()) { + return super.findDefaultValues(); + } else { + return null; + } } else { - return null; + /* Only use default values if the request is completely empty; + * this is different from what we do with the other input + * types, checking "defaults" when there's no value for the specific + * field. This difference is the result of the underlying + * inconsistency between checkboxes and everything else. + */ + if (!pageContext.getRequest().getParameterNames().hasMoreElements()) { + return super.findDefaultValues(); + } else { + return null; + } } } Modified: jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Form.java URL: http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Form.java?view=diff&rev=531148&r1=531147&r2=531148 ============================================================================== --- jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Form.java (original) +++ jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Form.java Sat Apr 21 23:19:13 2007 @@ -43,9 +43,29 @@ private String encType; // form encType - private String onsubmit, onreset, accept, acceptCharset; + private String onsubmit, onreset, acceptCharset; + /** + * Array indices to support array value input tags. That is tags with the same + * name being submitted, they become an array of values. This helps those tags + * repopulate correctly. + */ private Map arrayIndices; + + /** + * Set to true by input tags within this form if they detect that there + * are parameters in the request suggesting that this form can be repopulated + * from the request. This is used, specifically, by Checkbox to detect whether + * to use defaultValues or not. + */ + private boolean repopulating; + + /** + * Coupled with the repopulating flag, this indicates if a repopulating=false + * value is reliable. This is set to true when an input tag that can accurately + * detect whether there is a parameter in the request for it is encountered. + */ + private boolean repopulatingReliable; protected void init() { super.init(); @@ -54,13 +74,14 @@ encType = null; onsubmit = null; onreset = null; - accept = null; acceptCharset = null; - arrayIndices = null; } public int doStartTag() throws JspException { arrayIndices = null; + repopulating = false; + repopulatingReliable = false; + try { JspWriter out = pageContext.getOut(); @@ -78,7 +99,6 @@ printAttribute(out, "enctype", encType); printAttribute(out, "onsubmit", onsubmit); printAttribute(out, "onreset", onreset); - printAttribute(out, "accept", accept); printAttribute(out, "accept-charset", acceptCharset); out.print(">"); @@ -97,6 +117,20 @@ } return EVAL_PAGE; } + + /** + * Called by tags inside this form when they go looking for their value. + * This lets us update the repopulatingReliable flag. + * @param tag + */ + public void visitTag(BaseInputTag tag) { + if (pageContext.getRequest().getParameter(tag.getName()) != null) { + repopulating = true; + repopulatingReliable = true; + } else if (!(tag instanceof Checkbox)) { + repopulatingReliable = true; + } + } /** * Return the next index for a form element with the given name. This issues indices starting @@ -118,6 +152,14 @@ return 0; } } + + public boolean isRepopulating() { + return repopulating; + } + + public boolean isRepopulatingReliable() { + return repopulatingReliable; + } public void setAction(String x) { action = x; @@ -145,14 +187,6 @@ public String getAction() { return action; - } - - public String getAccept() { - return accept; - } - - public void setAccept(String accept) { - this.accept = accept; } public String getAcceptCharset() { Modified: jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Hidden.java URL: http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Hidden.java?view=diff&rev=531148&r1=531147&r2=531148 ============================================================================== --- jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Hidden.java (original) +++ jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Hidden.java Sat Apr 21 23:19:13 2007 @@ -43,7 +43,7 @@ out.print("<input type=\"hidden\""); printAttributes(out); - printAttribute(out, "value", findValue(), ""); + printAttribute(out, "value", findValue(true), ""); out.print(" />"); Modified: jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Password.java URL: http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Password.java?view=diff&rev=531148&r1=531147&r2=531148 ============================================================================== --- jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Password.java (original) +++ jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Password.java Sat Apr 21 23:19:13 2007 @@ -43,7 +43,7 @@ out.print("<input type=\"password\""); printAttributes(out); - printAttribute(out, "value", findValue(), ""); + printAttribute(out, "value", findValue(true), ""); out.print(" />"); } catch (IOException ex) { Modified: jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Radio.java URL: http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Radio.java?view=diff&rev=531148&r1=531147&r2=531148 ============================================================================== --- jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Radio.java (original) +++ jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Radio.java Sat Apr 21 23:19:13 2007 @@ -53,7 +53,12 @@ printAttributes(out); printAttribute(out, "value", value); - String target = findValue(); + /* Note that radio buttons cannot support the array mode of findValue, + * as it is expected that there will be multiple radio elements with + * the same name on the page; but they all particpate to select a single + * value. + */ + String target = findValue(false); if (target != null && target.equals(value)) { printAttribute(out, "checked", true); } Modified: jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Select.java URL: http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Select.java?view=diff&rev=531148&r1=531147&r2=531148 ============================================================================== --- jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Select.java (original) +++ jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Select.java Sat Apr 21 23:19:13 2007 @@ -69,19 +69,18 @@ printAttribute(out, "multiple", multiple); out.print(">"); - /* - * Print out our options, selecting one or more if appropriate. If - * there are multiple selections but the page doesn't call for a - * <select> that accepts them, ignore the selections. This is - * preferable to throwing a JspException because the (end) user can - * control input, and we don't want the user causing exceptions in - * our application. - */ - - String[] selected = findValues(); - - if (selected != null && selected.length > 1 && ((getAttributes() == null || !getAttributes().containsKey("multiple")) && !multiple)) - selected = null; + String[] selected; + if (multiple) { + selected = findValues(); + } else { + String selectedOne = findValue(true); + if (selectedOne != null) { + selected = new String[1]; + selected[0] = selectedOne; + } else { + selected = null; + } + } /* load up the selected values into a hash table for faster access * and for option tags to access Modified: jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Text.java URL: http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Text.java?view=diff&rev=531148&r1=531147&r2=531148 ============================================================================== --- jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Text.java (original) +++ jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/Text.java Sat Apr 21 23:19:13 2007 @@ -43,7 +43,7 @@ out.print("<input type=\"text\""); printAttributes(out); - printAttribute(out, "value", findValue(), ""); + printAttribute(out, "value", findValue(true), ""); out.print(" />"); } catch (IOException ex) { Modified: jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/TextArea.java URL: http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/TextArea.java?view=diff&rev=531148&r1=531147&r2=531148 ============================================================================== --- jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/TextArea.java (original) +++ jakarta/taglibs/proper/input/trunk/src/org/apache/taglibs/input/TextArea.java Sat Apr 21 23:19:13 2007 @@ -54,7 +54,7 @@ printAttribute(out, "rows", rows); out.print(">"); - String value = findValue(); + String value = findValue(true); if (value != null) { out.print(Util.quote(value)); } Modified: jakarta/taglibs/proper/input/trunk/xml/input.xml URL: http://svn.apache.org/viewvc/jakarta/taglibs/proper/input/trunk/xml/input.xml?view=diff&rev=531148&r1=531147&r2=531148 ============================================================================== --- jakarta/taglibs/proper/input/trunk/xml/input.xml (original) +++ jakarta/taglibs/proper/input/trunk/xml/input.xml Sat Apr 21 23:19:13 2007 @@ -348,13 +348,6 @@ </description> <availability>1.1</availability> </attribute> - <attribute> - <name>array</name> - <required>false</required> - <rtexprvalue>true</rtexprvalue> - <description>TODO</description> - <availability>1.2</availability> - </attribute> &attrs; &focus; @@ -818,13 +811,6 @@ <type>java.util.List</type> <description>options values for select</description> <availability>1.1</availability> - </attribute> - <attribute> - <name>array</name> - <required>false</required> - <rtexprvalue>true</rtexprvalue> - <description>TODO</description> - <availability>1.2</availability> </attribute> <attribute> <name>disabled</name> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]