File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Checkboxes in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Checkboxes in Struts" Watch "Checkboxes in Struts" New topic

Checkboxes in Struts

Stas Shvabsky

Joined: Feb 02, 2007
Posts: 5
I have a list of 0 or more of them assigned to the user. I need to show all sectors in the table.

First column is name of the sector second one is checkbox. Checkbox is checked if sector assigned to user. So format should be like this

<td>Sector 1 name</td>
<td><input type="checkbox" value="Sector 1 id"></td>
<td>Sector 2 name</td>
<td><input type="checkbox" value="Sector 2 id"></td>

How can I do it in Struts
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'd suggest using a combination of the <logic:iterate> tag or <c:forEach> if you prefer, and the <html:multibox> tag. Example:

Suppose you have a HashMap that contains a bunch of sectors for which each entry contains the sector id as the key and the sector name as the value, and that the hashmap is stored in request scope under the name "sectors". The following code would work:

When the user submits this form, your ActionForm's property "selectedSectors" will be a String array containing all the selected sector IDs.

See the heading "multibox" in this link for more information on the multibox tag.

Consultant, Sima Solutions
Stas Shvabsky

Joined: Feb 02, 2007
Posts: 5
Thank you it works
I agree. Here's the link:
subject: Checkboxes in Struts
jQuery in Action, 3rd edition