And it wont populate the unchecked ones... which means if each checkbox
doesnt have a unique value (ie: they all have value "true" or "on") you will
get an array containing n instances of "on" where n is equal to the number
of checked checkboxes of that name. Not very helpful.
Best bet is to give them individual values, or individual names, so you can
tell them apart when submitted.
ie: submission of the following:
<input type="checkbox" name="bob" value="on" checked="checked"/>
<input type="checkbox" name="bob" value="on"/>
<input type="checkbox" name="bob" value="on" checked="checked"/>
<input type="checkbox" name="bob" value="on" checked="checked"/>
<input type="checkbox" name="bob" value="on" checked="checked"/>
will give you:
bob == String[] { "on","on","on","on" }
The idea is to use something like:
<input type="checkbox" name="bob" value="1" checked="checked"/>
<input type="checkbox" name="bob" value="2"/>
<input type="checkbox" name="bob" value="3" checked="checked"/>
<input type="checkbox" name="bob" value="4" checked="checked"/>
<input type="checkbox" name="bob" value="5" checked="checked"/>
which will give you:
bob == String[] { "1","3","4","5" }
OR
<input type="checkbox" name="bob1" value="on" checked="checked"/>
<input type="checkbox" name="bob2" value="on"/>
<input type="checkbox" name="bob3" value="on" checked="checked"/>
<input type="checkbox" name="bob4" value="on" checked="checked"/>
<input type="checkbox" name="bob5" value="on" checked="checked"/>
bob1 == "on"
bob2 == null (assuming you reset it or its a request scoped form etc...)
bob3 == "on"
bob4 == "on"
bob5 == "on"
OR (maybe)
You could probably make use of indexed property names too (and init the
array of appropriate length in the reset method)
<input type="checkbox" name="bob[0]" value="on" checked="checked"/>
<input type="checkbox" name="bob[1]" value="on"/>
<input type="checkbox" name="bob[2]" value="on" checked="checked"/>
<input type="checkbox" name="bob[3]" value="on" checked="checked"/>
<input type="checkbox" name="bob[4]" value="on" checked="checked"/>
to get:
bob == String[] { "on",null,"on","on","on" }
Though I havent tried this variant, so I could be wrong, or the semantics
could be subtly different!
-----Original Message-----
From: Gurpreet Dhanoa [mailto:[EMAIL PROTECTED]
Sent: Thursday, 18 December 2003 15:58
To: Struts Users Mailing List; [EMAIL PROTECTED]
Subject: Re: Check-boxes and formbeans
hi
Just declare a property field with the datatype as array like
String[] mycheckBox
It will automatically populate all of the checkbox selected into the array
property
Regards
Gary
----- Original Message -----
From: "vasudevrao gupta" <[EMAIL PROTECTED]>
To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]>
Sent: Thursday, December 18, 2003 10:30 AM
Subject: Check-boxes and formbeans
>
> Hi All,
> I have many checkboxes with the same name in my html form. I use struts
> framework. When i submit the form, will i be able to access the
> checkboxes as an array in the form bean? Or should i have a seperate
> field for each checkbox in the formbean?
>
> Regards
> Vasudevrao gupta
>
>
> Confidentiality Notice
>
> The information contained in this electronic message and any attachments
to this message are intended
> for the exclusive use of the addressee(s) and may contain confidential or
privileged information. If
> you are not the intended recipient, please notify the sender at Wipro or
[EMAIL PROTECTED] immediately
> and destroy all copies of this message and any attachments.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]