}
public void decode(FacesContext context, UIComponent component,
CompositeRenderer compositeRenderer) {
UIScrollableDataTable grid = (UIScrollableDataTable) component;
ExternalContext externalContext = context.getExternalContext();
Map requestParamMap = externalContext.getRequestParameterMap();
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();
}
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();
}
},
state);
} catch(IOException e) {
throw new FacesException(e);
}
grid.setSelection(simpleSelection);
ValueBinding selectionBinding = grid.getValueBinding("selection");
if (selectionBinding != null) {
selectionBinding.setValue(context, simpleSelection);
}
ScrollableDataTableRendererState.restoreState(context);