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();
}
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);
}
state.nextRow();