0

I would like to do multiple rows selection. Rows are display through strut2 tag s:iterator, how can I get the selection information, which should contains a list of selected "id"

<s:form action='Selection'>
<s:iterator value="transInfos"> 
  <input type='hidden' name=id value='<s:property value="id" />' />
  <s:checkbox name="selected"/>
  <s:property value="name" />
</s:iterator>
<s:submit value="Selection" />
</s:form>
Jenny
  • 107
  • 2
  • 11

2 Answers2

0

One option which seems to me is to create a hidden field in your form like

<s:form action="selection">
<input type='hidden' name="selectedId" value=""/>
</s:form>

you can add a on-click event to your check-box and if it get checked you can add the value t a variable and set in the hidden field,each new addition should be added as new values in comma separated way like in end hidden field should be like

<input type='hidden' name="selectedId" value="1,2,3,4"/>

moment you submit the form you can parse the form value and can split it based on the separator ","

other option is to name the check-box with same name so moment it will get submitted the values of the checked one will be submitted as a collection, choice is all yours and you need to decide which way to go

Umesh Awasthi
  • 23,407
  • 37
  • 132
  • 204
0

I'm glad I can answer this question myself. The answer is quite simple.

<s:form action="..." >
 <s:iterator value="transInfos">
  <input type="checkbox" name="transIds" value='<s:property value="transID" />'/>
 </s:iterator>                          
 <s:submit value="Select"/>
</s:form>

the value of checkbox is what you want to pass to the action, all the selected checkboxes will pass their values as a list to the action.

Jenny
  • 107
  • 2
  • 11