5 Replies Latest reply on Nov 17, 2008 7:05 AM by Yu Sun

    question about dynamic tree node in richfaces with ajax

    Yu Sun Newbie

      hi everyone
      I'm a beginner in richfaces and I need some help.
      I wanna make a tree which its TreeNode s (leaves) are added incrementaly by clicking on them with ajax technology.
      I used this code but I didn't see any reply

      <rich:tree style="width:300px" value="#{yegan.tree}" binding="#{yegan.htmlTree}" var="item" >
      <rich:treeNode changeExpandListener="#{yegan.changed}">// changed() adds treeNodes
      <h:outputText value="#{item.name}"/>
      </rich:treeNode>
      </rich:tree>

      I would be very thankful to you
      thanks and regards

        • 1. Re: question about dynamic tree node in richfaces with ajax
          Ilya Shaikovsky Master

          why you just can't define the full tree. Using ajax switchType only expanded node children will be loaded out of the box..?

          • 2. Re: question about dynamic tree node in richfaces with ajax
            Yu Sun Newbie

             

            "ilya_shaikovsky" wrote:
            why you just can't define the full tree. Using ajax switchType only expanded node children will be loaded out of the box..?

            There're about 5000 tree nodes.
            Query costs too much time.

            • 3. Re: question about dynamic tree node in richfaces with ajax
              Nick Belaevski Master

              Hi,

              Tree is initialized lazily by default. Only the nodes actually rendered are processed, so you can implement getChildren/getChild/isLeaf methods of TreeNode to implement lazy loading.

              However what are the problems with changeExpandListener? Can you please provide code for it?

              • 4. Re: question about dynamic tree node in richfaces with ajax
                Yu Sun Newbie

                 

                <rich:tree style="width:300px" value="#{ajaxTreeBean.treeNode}"
                 var="item" nodeFace="#{item.type}" switchType="ajax" rendered="true" immediate="false">
                 <rich:treeNode type="latn" iconLeaf="/images/tree/singer.gif"
                icon="/images/tree/singer.gif" changeExpandListener="#{ajaxTreeBean.processExpand}">
                 <h:outputText value="#{item.latn_name}" />
                 </rich:treeNode>
                </rich:tree>

                public void processExpand(NodeExpandedEvent event) {
                 DatabaseAccess dba = new DatabaseAccess(StaticJNDI.LOCAL_DS_NAME);
                 Integer count_a = new Integer(1);
                 TreeNode tree = (TreeNode) event.getComponent();
                 Map latnMap = (Map) tree.getData();
                 Integer latn_id = ((Number) latnMap.get("LATN_ID")).intValue();
                 List area_list = dba
                 .doQueryAll("select * from area a where a.latn_id = " + latn_id);
                 Iterator iterator_a = area_list.iterator();
                 while (iterator_a.hasNext()) {
                 TreeNodeImpl nodeImpl_a = new TreeNodeImpl();
                 Map areaMap = (Map) iterator_a.next();
                 nodeImpl_a.setData(areaMap);
                 tree.addChild(count_a, nodeImpl_a);
                 count_a++;
                 }
                
                 }


                it doesn't work

                • 5. Re: question about dynamic tree node in richfaces with ajax
                  Yu Sun Newbie

                   

                  "nbelaevski" wrote:
                  Hi,

                  Tree is initialized lazily by default. Only the nodes actually rendered are processed, so you can implement getChildren/getChild/isLeaf methods of TreeNode to implement lazy loading.

                  However what are the problems with changeExpandListener? Can you please provide code for it?

                  Thank you for help! I'll try.