This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Struts and the fly likes multiple Checkbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "multiple Checkbox" Watch "multiple Checkbox" New topic

multiple Checkbox

sudharshan tettu
Ranch Hand

Joined: Jul 17, 2006
Posts: 124
I have an array of checkbox in my application when the form is sbumittied how to get ,which checkbox is selected in my action class

form bean:-
String[] checkThis=null;

on my jsp
<logic:iterate name="row" />
<html:checkbox property="checkThis" />

how to get the index of checked checkbox
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you're iterating over a list of beans and the checkbox represents a boolean value in one of those beans, you should use <html:checkbox> and specify an indexed property as the property. This link will show you how to use indexed properties.


<logic:iterate id="user" name="users" >
<html:checkbox name="user" property="registered" indexed="true" value="true" />

If you have a situation where the user is selecting one or more values from a list of possible values, you should use the <html:multibox> tag instead of <html:checkbox>. Use the same property nane for each tag, and make sure the value="" is different for each iteration of the tag. In your ActionForm make sure the property used by the checkboxes is of type String[]. When the form is submitted, your ActionForm will contain an array containing one element for each checked box that contains the value specified for that box.


<hml:multibox property="color" value="blue" />
<hml:multibox property="color" value="green" />
<hml:multibox property="color" value="yellow" />
<hml:multibox property="color" value="red" />
[ July 20, 2006: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
sudharshan tettu
Ranch Hand

Joined: Jul 17, 2006
Posts: 124
thanks for ur timely reply....
it was a big help to my problem....
I agree. Here's the link:
subject: multiple Checkbox