2 Replies Latest reply on Oct 2, 2009 5:58 AM by Ilya Shaikovsky

    Problem with dynamic add nodes with rich:tree

    Chen Xi Newbie

      Currently I am developing dynamic tree menu. Due to the large data, I can only load and display the first level data. Only when user expand the second level of the node, back end service will fetch data back. Now the problem is I have already add the data to the TreeNode object, however the UI does not render the new nodes to the tree.

      Any one can help me to solve the problem?

      I am using richfaces-api-3.3.1GA & richfaces-impl-3.3.1 GA

      Here is my code


       <!--<a4j:region renderRegionOnly="true" id="ajaxRegionId">-->
       <a4j:outputPanel ajaxRendered="true">
       <rich:tree id="clientTree" value="#{clientTreeController.clients}" var="item"
       reRender="NodeId" ajaxSubmitSelection="true" switchType="ajax"
       treeNodeVar="TreeNodeVar" ajaxKeys="#{null}">
       <rich:treeNode id="treeNodeId" iconLeaf="/img/Transpusers.png"
       <h:outputText id="NodeId" value="#{item}"/>


       public void viewUsers(NodeExpandedEvent evt) throws IOException {
       System.out.println("Execute viewUsers method");
       Object source = evt.getSource();
       if (source instanceof HtmlTreeNode) {
       UITree tree = ((HtmlTreeNode) source).getUITree();
       if (tree == null) {
       Object rowKey = tree.getRowKey();
       TreeNode selectedTreeModelNode = tree.getModelTreeNode(rowKey);
       if (null != selectedTreeModelNode) {
       System.out.println("The selected node has child [" + selectedTreeModelNode.getChildren().hasNext()+"]");
       String companyName = (String) selectedTreeModelNode.getData();
       Client client = clientManager.getClientByName(companyName);
       List<UserEntityData> users = client.getUsers();
       if (users == null) return;
       for (int k = 0; k < users.size(); k++) {
       TreeNodeImpl userNode = new TreeNodeImpl();
       selectedTreeModelNode.addChild(k, userNode);
       } else {
       System.out.println("selectedTreeNode is null");