Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top