checkbox struts 2 example
check box in struts2 is stateful mean we can get default selected check box with defining in checkbox tag. check box use with list option where can define value and id of the checkbox option.
Example will show you how to use check box in struts2
<s:checkboxlist name="smonth" list="#{'1':'Jan','2':'Feb','3':'Mar'}" value="2" />

- 1. list will set checkbox with value and label
- 2. value is attribute which set default selected value of option in check box, if we set 2 value it will automatically selected Feb month checkbox
Tags: Struts



Link to Us
How can I make more than one checkbox selected, i tried to seperate them by comma like:
value=’2,3′
but didn’t work, it selected only the checkbox with id 3
Regards
I found the answer,
I used a Map<key,value> to hold the list of selected checkboxes, example:
in the action we declare:
HashMap selected = new HashMap();
in the function we put:
selected.put(”1″, “1″);
selected.put(”3″, “3″);