You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Laine Donlan <ld...@elogex.com> on 2001/02/20 14:19:41 UTC

Support for submitting unchecked checkboxes

In order to capture the act of a user unchecking checkboxes and to
initialize the checkbox as checked/unchecked with non boolean values I
made a couple of changes to the
org.apache.struts.taglib.html.CheckboxTag.  

Basically the changes consisted of:

1) Using the supplied value attribute to match against the bean property
value and generating the 'checked' attribute accordingly.  If the value
is not supplied then the previously implemented method of checking 'on',
'true', or 'yes' is performed.  So I do not think that default behavior
should be affected.

2) Added support for two new attributes - submitUnchecked (boolean) and
uncheckedValue (String).  Neither of these attributes are required and
the submitUnchecked defaults to 'false'.  If a user chooses to submit
unchecked values then two form inputs will be generated that facilitate
this function.  See below for an example:

Tag notation -
<html:checkbox  name="bean" property="indexedBean.property"
submitUnchecked="true" uncheckedValue="0" value="1"/>

Generated HTML -
<input type="checkbox" name="indexedBean.property_checkBox" value="1" 
	
onclick="(this.checked?this.form['indexedBean.property'].value='1':this.
form['indexedBean.property'].value='0')">
<input type="hidden" name="indexedBean.property" value="0"/> (where 0 is
the current value of the bean property)

So in this scenario the actual checkbox param in the request will be
ignored and the hidden input will be used to maintain the bean property
that the user wishes.

In the case where the user does not provide the two new attributes the
html will be generated as it is today with the exception of the
determination of the checked or unchecked mentioned above.

I could not see how this functionality was present in the current
checkbox tag without explicitly declaring two tags and adding javascript
to the checkbox tag.  Even then some scripting may be required to
differentiate between the two inputs and to initialize the hidden one.
If I missed something could someone point me in the right direction.  I
have attached the CheckboxTag.java file for review and use if anyone is
interested.
 <<CheckboxTag.zip>> 
Thanks.  Comments would be appreciated.

Laine

Re: Support for submitting unchecked checkboxes

Posted by Johan Compagner <jc...@j-com.nl>.
+1

Please insert this (or something like this) in the 1.0 code base, because
checkboxes are useless at this time to use!!

johan

----- Original Message -----
From: "Laine Donlan" <ld...@elogex.com>
To: "Struts Dev (E-mail)" <st...@jakarta.apache.org>
Sent: Tuesday, February 20, 2001 2:19 PM
Subject: Support for submitting unchecked checkboxes


In order to capture the act of a user unchecking checkboxes and to
initialize the checkbox as checked/unchecked with non boolean values I
made a couple of changes to the
org.apache.struts.taglib.html.CheckboxTag.

Basically the changes consisted of:

1) Using the supplied value attribute to match against the bean property
value and generating the 'checked' attribute accordingly.  If the value
is not supplied then the previously implemented method of checking 'on',
'true', or 'yes' is performed.  So I do not think that default behavior
should be affected.

2) Added support for two new attributes - submitUnchecked (boolean) and
uncheckedValue (String).  Neither of these attributes are required and
the submitUnchecked defaults to 'false'.  If a user chooses to submit
unchecked values then two form inputs will be generated that facilitate
this function.  See below for an example:

Tag notation -
<html:checkbox  name="bean" property="indexedBean.property"
submitUnchecked="true" uncheckedValue="0" value="1"/>

Generated HTML -
<input type="checkbox" name="indexedBean.property_checkBox" value="1"

onclick="(this.checked?this.form['indexedBean.property'].value='1':this.
form['indexedBean.property'].value='0')">
<input type="hidden" name="indexedBean.property" value="0"/> (where 0 is
the current value of the bean property)

So in this scenario the actual checkbox param in the request will be
ignored and the hidden input will be used to maintain the bean property
that the user wishes.

In the case where the user does not provide the two new attributes the
html will be generated as it is today with the exception of the
determination of the checked or unchecked mentioned above.

I could not see how this functionality was present in the current
checkbox tag without explicitly declaring two tags and adding javascript
to the checkbox tag.  Even then some scripting may be required to
differentiate between the two inputs and to initialize the hidden one.
If I missed something could someone point me in the right direction.  I
have attached the CheckboxTag.java file for review and use if anyone is
interested.
 <<CheckboxTag.zip>>
Thanks.  Comments would be appreciated.

Laine