@Override
public void doDecode(FacesContext context, UIComponent component) {
Map<String, String> map = context.getExternalContext().getRequestParameterMap();
String selectedNode = map.get(getSelectionStateInputId(context, component));
AbstractTree tree = (AbstractTree) component;
Object selectionRowKey = null;
if (!Strings.isNullOrEmpty(selectedNode)) {
RowKeyContextCallback rowKeyContextCallback = new RowKeyContextCallback();
tree.invokeOnComponent(context, selectedNode, rowKeyContextCallback);
selectionRowKey = rowKeyContextCallback.getRowKey();
}
Collection<Object> selection = tree.getSelection();
Collection<Object> newSelection = null;
if (selectionRowKey == null) {
if (!selection.isEmpty()) {
newSelection = Collections.emptySet();
}
} else {
if (!selection.contains(selectionRowKey)) {
newSelection = Collections.singleton(selectionRowKey);
}
}
if (newSelection != null) {
new TreeSelectionChangeEvent(component, Sets.newHashSet(selection), newSelection).queue();
}
PartialViewContext pvc = context.getPartialViewContext();
if (pvc.isAjaxRequest()) {
pvc.getRenderIds().add(
tree.getClientId(context) + MetaComponentResolver.META_COMPONENT_SEPARATOR_CHAR
+ AbstractTree.SELECTION_META_COMPONENT_ID);
}
}