private void encodeSelection(FacesContext context, UIScrollableDataTable grid) throws IOException {
final ScrollableDataTableRendererState state = ScrollableDataTableRendererState.createState(context, grid);
state.setRowIndex(ScrollableDataTableUtils.getClientRowIndex(grid));
final Selection gridSelection =
grid.getSelection() == null ?
new SimpleSelection() :
grid.getSelection();
final ClientSelection clientSelection = new ClientSelection();
grid.walk(context,
new DataVisitor() {
public void process(FacesContext context, Object rowKey,
Object argument) throws IOException {
if (gridSelection.isSelected(rowKey)) {
int i = state.getRowIndex();
clientSelection.addIndex(i);
}