}
protected void encodeTreeNode(FacesContext facesContext, UIComponent component, DefaultMutableTreeNode treeNode,
int rank,String idPath) throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
String clientId = component.getClientId(facesContext);
TreeNode[] path = treeNode.getPath();
for (int j = 1; j < path.length; j++) {
TreeNode pathNode = path[j];
clientId = clientId + ":_id" + pathNode.getParent().getIndex(pathNode);
}
String var = (String) component.getParent().getAttributes().get("var");
Object userObject = treeNode.getUserObject();
facesContext.getExternalContext().getSessionMap().put(var, userObject);
TreeItemComponent treeItemComponent = (TreeItemComponent) component.getChildren().get(0);
treeItemComponent.setPath(idPath);
treeItemComponent.setCurrentTreeNode(treeNode);
if (treeItemComponent.isRendered()) {
treeItemComponent.encodeBegin(facesContext);
treeItemComponent.encodeChildren(facesContext);
if (treeNode.getChildCount() > 0) {
responseWriter.startElement("treechildren",null);
for (int i = 0; i < treeNode.getChildCount(); i++) {
DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) treeNode.getChildAt(i);
StringBuffer pathBuffer = new StringBuffer(idPath);
pathBuffer.append("_");
pathBuffer.append(i);
encodeTreeNode(facesContext, component, childNode, i,pathBuffer.toString());
}
responseWriter.endElement("treechildren");
}
treeItemComponent.encodeEnd(facesContext);
}
}