This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiple Checkbox

 
sudharshan tettu
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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" />
</logic:iterate>

how to get the index of checked checkbox
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

example:

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

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.

example:

<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 ]
 
sudharshan tettu
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for ur timely reply....
it was a big help to my problem....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic