@Override
public void decode(FacesContext facesContext, UIComponent component) {
super.decode(facesContext, component);
TreeComponent treeComponent = (TreeComponent) component;
treeComponent.setSelectionPath(null);
if (isSubmitted(facesContext, component)) {
Map paramMap = facesContext.getExternalContext().getRequestParameterMap();
String clientId = component.getClientId(facesContext);
if (paramMap.containsKey(clientId)) {
String selection = (String) paramMap.get(clientId);
if ((selection != null) && (selection.length() > 0)) {
String selections[] = selection.split(" ");
if (selections != null) {
// Get multi selections
TreePath[] selectionPaths = new TreePath[selections.length];
for (int i = 0; i < selections.length; i++) {
int tiIndex = selections[i].lastIndexOf("ti_");
if (tiIndex != -1) {
String path[] = selections[i].substring(tiIndex+3).split("_");
TreeNode selectedNodes[] = new TreeNode[path.length];
TreeNode currentNode = (TreeNode) treeComponent.getTreeModel().getRoot();
selectedNodes[0] = currentNode;
for (int j = 0; j < path.length; j++) {
String number = path[j];
int index = Integer.parseInt(number);
if (index < currentNode.getChildCount()) {
selectedNodes[j] = currentNode.getChildAt(index);
currentNode = selectedNodes[j];
}
}
selectionPaths[i] = new TreePath(selectedNodes);
}
}
treeComponent.setSelectionPath(selectionPaths);
}
}
}
Set<Entry> entries = paramMap.entrySet();
for (Entry entry : entries) {
String key = (String) entry.getKey();
if (key.startsWith(clientId)) {
treeComponent.getAttributes().put(key, entry.getValue());
}
}
}
}