checkbox - Get/set multiple struts2 checkboxes to/from list -


i´m developing struts2 app user make 1 of 3 choices, , based on choice number of different predefined checkboxes presented. of checkboxes appear regardless of choice made, while others unique each choice can made. in total, there around 50 different checkboxes, , each checkbox have id, 1 50.

the selections made user persisted rows in database, , need able repopulate selected checkboxes should user want change selections made.

using checkboxlist not suitable, need put checkboxes different fieldsets on page. guess i´m stuck regular .

now, has got idea of how could: 1) retrieve selected checkboxes, preferebly putting them list/set in action 2) repopulate selected checkboxes list selections has been stored?

any ideas appreciated!

1) retrieve selected checkboxes, use (supposing you're using jsp):

<input type="checkbox" name="yourname" id="checkbox-1" value="1" /> <input type="checkbox" name="yourname" id="checkbox-2" value="2" /> <input type="checkbox" name="yourname" id="checkbox-3" value="3" /> etc... 

in action class, can retrieve variable "yourname" arraylist of integers instance, automatically populated checked checkbox ids struts2.

2) repopulate checkboxes on edit page instance, there many possible solutions (could give more details architecture, objects, , on?)

in action class, retrive in list ids of formerly-checked checkboxes (let's call selectedlist).once on jsp view, add "checked="checked"" parameter checkbox field on condition id of box contained in selectedlist. should work:

<s:if test="'checkboxid' in selectedlist">checked="checked"</s:if>  

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -