This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Struts and the fly likes Checkboxes in Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "Checkboxes in Struts" Watch "Checkboxes in Struts" New topic
Author

Checkboxes in Struts

Stas Shvabsky
Greenhorn

Joined: Feb 02, 2007
Posts: 5
Hi.
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

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

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.


Merrill
Consultant, Sima Solutions
Stas Shvabsky
Greenhorn

Joined: Feb 02, 2007
Posts: 5
Thank you it works
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Checkboxes in Struts
 
Similar Threads
Need Help with binding click events to table rows
Getting the TD value using JavaScript + TD does not contain any ID.
How to catch checkbox value
Parsing the DOM
Having some multidimensional array problem in JSP