This small application demonstrates how to use the new AWGrid component.
First of all, you need to add an AWGrid to your actionForm, along with its getters and setters.
Also, don't forget to set the dataClass in the reset() method.
private AwGrid dataGrid;
public void setDataGrid(AwGrid dataGrid) {
this.dataGrid = dataGrid;
}
public AwGrid getDataGrid() {
return dataGrid;
}
public void reset(ActionMapping mapping, HttpServletRequest request){
dataGrid = new DefaultAwGrid();
dataGrid.setDataClass(SampleBean.class);
}
In your JSP don't forget to include the method addFields with your onsubmit event handler (So you can catch the changes in the server side)
<html:form action="/DataGridSampleAction" onsubmit="addFields(this);return true;">
Finally, in your Action class you can retrieve the values that were submitted.
For example, if you want to retrieve a list the modified rows, just type:
list = (List) grid.get(GridConstants.MODIFIED);
If you want to retrieve the created rows, you type:
list = (List) grid.get(GridConstants.NEW);
To retrieve the deleted rows, type:
list = (List) grid.get(GridConstants.DELETED);
If you ever want to retrieve the rows that weren't modified:
list = (List) grid.get(GridConstants.UNTOUCHED);
If you want the complete list (no matter its state) type:
list = (List) grid.getDataList();
Simple, isn't it?