• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Checkboxes in Struts

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Stas Shvabsky
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you it works
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic