Sunday, August 29, 2010

Struts 2 Mapping a bulk of entries in a JSP to an array in an Action Class

To pass selected multiple entries which are in a JSP to the action in order to process all of them rather than processing one by one following sample codes can be used.

In the JSP code following has to be kept. Here it is having only the required fields to handle the this thing. Additional stuff has to be added by yourselves :
fileldValue : value in this will be mapped to a particular index in a "bulk" array which is in the action class here "key" is a long value in a request.

<s:checkbox name="bulk" value="%{#bulk}" fieldValue="{#key}"/>

In the action class there should have an array to map the selected entries in the JSP.

public class BulkHandler extends ActionSupport {

private long[] bulk;

public long[] getBulk() {
        return bulk;
    }

public void setBulk(long[] bulk) {
        this.bulk = bulk;
    }

/**
* @return String which desides the next page
*/
public String ProcessBulk(){

/* here you can process the bulk array which is having the long parameter values of every entries  which were selected and sent to the action from the jsp */

   return  SUCCESS;
                    }

}