4 Replies Latest reply on Mar 27, 2008 9:38 AM by Cosmin Juravle

    RichFaces Tree: How to

    Cosmin Juravle Newbie

      Hi,

      I have a rich:tree lazy loaded from db via ajax switch type.

      The code for it looks something like:

      <rich:tree id="myTree" var="node" selectedClass="selectedNode"
       switchType="ajax"
       showConnectingLines="true"
       status="commonstatus"
       style="width:600px"
       ajaxSubmitSelection="true"
       value="#{treeBean3.treeNode}">
       <rich:treeNode selectedClass="selected_node">
       <h:outputText value="#{node}" style="font-size: 8pt;"/>
       </rich:treeNode>
       </rich:tree>


      I used lazy loading of the model because I don't have the nodes up front. Getting the children of each other node is a database call with a lot of children, so getting the tree all up front is not an option.

      I have the following problem:

      I need to "Go To" a specific node in the tree, based on an text input on top of the page.

      Something like:

      <h:inputText id="selectedNode"/>
       <a4j:commandButton actionListener="#{treeBean3.gotoAction}" value="Go To"
       status="commonstatus" reRender="myTree"/>
      


      On push of the "Go To" button, I am getting the UITree component from my page, but I cannot find a way to "expand" the specific node searched (based on the label of the node).

      Is there any way, that given a precise node (it's ID, Identifier or label), you could programatically expand it?
      Moreover, if your tree is lazy loaded (meaning expansion is done level after level based on user click), how can I scroll (navigate) programatically to a specific node and fire a expansion event there?

      Thank you,
      Cosmin.

        • 1. Re: RichFaces Tree: How to
          Cosmin Juravle Newbie

          I have been trying without success, to use queueNodeExpand on the UITree, based on the user input.

          The "goto" action method is something like:

          public void gotoAction(ActionEvent ae) {
           HtmlTree htmlTree = null;
          
           HtmlInputText input = null;
          
           HtmlAjaxCommandButton button = (HtmlAjaxCommandButton) ae.getSource();
           HtmlForm htmlForm = (HtmlForm) button.getParent();
           for(UIComponent component : htmlForm.getChildren()) {
           if(component instanceof HtmlTree) {
           htmlTree = (HtmlTree) component;
           }
           else if(component instanceof HtmlInputText) {
           input = (HtmlInputText) component;
           }
           }
          
           String val = "" + input.getSubmittedValue();
          
          
           // manually expand now
           TreeRowKey trk = new ListRowKey(htmlTree.getId()+":" + val);
          
           try {
           htmlTree.queueNodeExpand(trk);
           } catch(IOException e) {
           log.error(e, e);
           }
           }


          The goal of the above code:
          - expand node with TreeRowKey equals to the one calculated as path=TREE_ID:NODE_IDENTIFIER.

          I deducted this info from looking with the debugger to the TreeRowKeys of other rendered nodes.

          Could anyone please help me on this matter, or let me know why isn't queueNodeExpanded working as expected?

          P.S.: The equals() implementation of TreeRowKey is based on path.equals() so this logic should work correctly.

          What am I missing?

          • 2. Re: RichFaces Tree: How to
            Cosmin Juravle Newbie

            Please, does anybody have a working example of a simple rich:tree which can be expanded based on a Node Identifier (TreeRowKey) ?

            Thank you,
            Cosmin.

            • 3. Re: RichFaces Tree: How to
              aaa aaa Newbie

              Salut,

              http://labs.jboss.com/wiki/ExpandCollapseTreeNodes

              I tryed that and is working for me using adviseNodeOpened attribute.

              Bafta

              • 4. Re: RichFaces Tree: How to
                Cosmin Juravle Newbie

                Merci,
                I'll look into it.