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