String parentClientId = null;
if (parent != null && parent instanceof UITreeNode) { // if not the root node
parentClientId = treeNode.getParent().getClientId(facesContext);
}
UITree root = treeNode.findTreeRoot();
String rootId = root.getClientId(facesContext);
String jsClientId = TreeRenderer.createJavascriptVariable(clientId);
String jsParentClientId = TreeRenderer.createJavascriptVariable(
parentClientId);
// rootId = HtmlUtils.createJavascriptVariable(rootId);
TreeState treeState = root.getState();
if (treeState == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("No treeState found. clientId=" + clientId);
}
} else {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeNode.getValue();
ResponseWriter writer = facesContext.getResponseWriter();
String debuging = null;
writer.writeText("var ", null);
writer.writeText(jsClientId, null);
writer.writeText(" = new ", null);
if (component.getChildCount() == 0) {
writer.writeText("TreeNode", null);
} else {
writer.writeText("TreeFolder", null);
}
writer.writeText("('", null);
Object name = treeNode.getAttributes().get(ATTR_NAME);
if (LOG.isDebugEnabled()) {
debuging += name + " : ";
}
if (name != null) {
writer.writeText(StringEscapeUtils.escapeJavaScript(name.toString()), null);
} else {
LOG.warn("name = null");
}
writer.writeText("','", null);
writer.writeText(clientId, null);
writer.writeText("',", null);
writer.writeText(Boolean.toString(!root.isShowIcons()), null);
writer.writeText(",", null);
writer.writeText(Boolean.toString(!root.isShowJunctions()), null);
writer.writeText(",", null);
writer.writeText(Boolean.toString(!root.isShowRootJunction()), null);
writer.writeText(",", null);
writer.writeText(Boolean.toString(!root.isShowRoot()), null);
writer.writeText(",'", null);
writer.writeText(rootId, null);
writer.writeText("',", null);
String selectable = ComponentUtil.getStringAttribute(root, ATTR_SELECTABLE);
if (selectable != null
&& (!(selectable.equals("multi") || selectable.equals("multiLeafOnly")
|| selectable.equals("single") || selectable.equals("singleLeafOnly")
|| selectable.equals("sibling") || selectable.equals("siblingLeafOnly")))) {
selectable = null;
}
if (selectable != null) {
writer.writeText("'", null);
writer.writeText(selectable, null);
writer.writeText("'", null);
} else {
writer.writeText("false", null);
}
writer.writeText(",", null);
writer.writeText(Boolean.toString(ComponentUtil.getBooleanAttribute(root,
ATTR_MUTABLE)), null);
writer.writeText(",'", null);
writer.writeText(
ComponentUtil.findPage(component).getFormId(facesContext), null);
writer.writeText("',", null);
if (component.getChildCount() == 0
|| (selectable != null && !selectable.endsWith("LeafOnly"))) {
boolean selected = treeState.isSelected(node);
writer.writeText(Boolean.toString(selected), null);
if (LOG.isDebugEnabled()) {
debuging += selected ? "S" : "-";
}
} else {
writer.writeText("false", null);
if (LOG.isDebugEnabled()) {
debuging += "-";
}
if (treeState.isSelected(node)) {
LOG.warn("Ignore selected FolderNode in LeafOnly selection tree!");
}
}
writer.writeText(",", null);
writer.writeText(Boolean.toString(treeState.isMarked(node)), null);
if (component.getChildCount() > 0) {
writer.writeText(",", null);
boolean expanded = treeState.isExpanded(node);
writer.writeText(Boolean.toString(expanded), null);
if (LOG.isDebugEnabled()) {
debuging += expanded ? "E" : "-";
}
}
writer.writeText(",", null);
writer.writeText(Boolean.toString(root.isRequired()), null);
writer.writeText(",treeResourcesHelp);\n", null);
if (jsParentClientId != null) { // if not the root node
writer.writeText(jsParentClientId, null);
writer.writeText(".add(", null);