Search code examples
tagsiteratorstrutsselectionognl

How to use struts tag iterator and OGNL to realize multiple rows selection


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>

Solution

  • 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.