Application application = context.getApplication();
String id = getSelectionInputName(context, grid);
String value = (String) requestParamMap.get(id);
Converter converter = application
.createConverter(ClientSelection.class);
ClientSelection _oldClientSelection = (ClientSelection) grid
.getAttributes().get(CLIENT_SELECTION);
final ClientSelection oldClientSelection = _oldClientSelection == null ? new ClientSelection()
: _oldClientSelection;
final ClientSelection clientSelection = (ClientSelection) converter
.getAsObject(context, grid, value);
final ScrollableDataTableRendererState state = ScrollableDataTableRendererState
.createState(context, grid);
state.setRowIndex(ScrollableDataTableUtils.getClientRowIndex(grid));
final SimpleSelection simpleSelection = grid.getSelection() == null ? new SimpleSelection()
: (SimpleSelection) grid.getSelection();
if (clientSelection.isReset() || clientSelection.isSelectAll()) {
simpleSelection.clear();
simpleSelection.setSelectAll(clientSelection.isSelectAll());
}
try {
grid.walk(context, new DataVisitor() {
public void process(FacesContext context, Object rowKey,
Object argument) throws IOException {
int i = state.getRowIndex();
if (shouldAddToSelection(i, oldClientSelection,
clientSelection)) {
simpleSelection.addKey(rowKey);
} else if (shouldRemoveFromSelection(i,
oldClientSelection, clientSelection)) {
simpleSelection.removeKey(rowKey);
}
if (i == clientSelection.getActiveRowIndex()) {
grid.setActiveRowKey(rowKey);
}
state.nextRow();
}