How can i get checkbox values from struts2 checkbox in displaytag to action class

萝らか妹 提交于 2019-12-01 10:25:36

问题


I am working on struts2 application in which i am using displaytag for pagination support.

Now i want a check box for each row in the table for that i am doing this.

<display:table name="countryList" export="true" class="table" id="countryList" pagesize="${selectedPageSize}" decorator="org.displaytag.decorator.TotalTableDecorator" >        
    <display:column property="id"  title="ID" paramId="id" />
    <display:column property="name" title="Name"  sortable="true"/>
    <display:column title="Delete All">
        <s:checkbox  id="check" name="check" fieldValue="%{#attr.countryList.id}" theme="simple"/>
    </display:column>
</display:table>  

<s:submit action="deleteall"  value="DeleteSelected" />

till here its work fine. now i want to delete all the countries that are checked through the check box.

for that i want the ids of the countries that are checked .for that i have to take the values in an array.

The problem is how can i send the values from jsp and then get it at the action class


回答1:


If you add a String[] to your action named the same as your checkbox(s) and expose it via accessors (getters/setters) struts 2 should auto populate it.




回答2:


This is how I would do it.

  1. instead of 'id' for all id columns, append a sequence number so that each id has a unique name, such as 'id1', 'id2' etc

  2. create a interceptor that collects values of parameters prefixed with 'id'

  3. configure your action to use the interceptor

My strut fu is rusty though. There probably is a better way.



来源:https://stackoverflow.com/questions/798118/how-can-i-get-checkbox-values-from-struts2-checkbox-in-displaytag-to-action-clas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!