4 Replies Latest reply on Mar 3, 2009 2:09 PM by Johan Borchers

    rerender a specific treenode or whole tree?

    Johan Borchers Newbie

      Hello,

      Does anyone know if it's possible to rerender a specific node?

      I have a panel with update fields in the following form :

      <a4j:form id="ajaxSubmitTrueForm" ajaxSubmit="true" reRender="#{programmeHandler.renderNodesList}">
      


      Clicking on a node adds the id to the rerender list:

      public void selectItem(NodeSelectedEvent e) {
       renderNodesList.clear();
       renderNodesList.add(e.getComponent().getId());
      }
      


      But then I get the error :

      2-mrt-2009 18:29:34 com.sun.facelets.FaceletViewHandler handleRenderException
      SEVERE: Error Rendering View[/pages/programme.xhtml]
      java.lang.IllegalStateException: No tree element available or row key not set!
      at org.richfaces.model.TreeDataModel.isLeaf(TreeDataModel.java:301)
      at org.richfaces.component.UITree.isLeaf(UITree.java:534)

      Rerendering works only with referencing the whole tree.

      T.I.A.

      Johan Borchers

        • 1. Re: rerender a specific treenode or whole tree?
          Nick Belaevski Master

          Hello Johan,

          Yes, it's possible. Use "ajaxKeys" attribute to define a set of row keys that will be updated by the current AJAX request. Row key is analog of row index used for "flat" data table models; that is an entity that tree model creates in order to locate the particular tree node. Row key for the current node (tree listeners are called in the context of particular node) can be obtained by calling UITree#getRowKey method.

          • 2. Re: rerender a specific treenode or whole tree?
            Johan Borchers Newbie

            Hello,

            Can you tell a little bit more because I did read the ajaxKeys in the book of Max Katz but I'm not able to reflect this on the tree.
            Or where can I find an example?

            I was able to get the row key via tree.getRowKey() but what to do with that?

            ajaxKeys and ajaxNodeKeys are mentioned in the documentation but how to use it?
            Should I use ajaxKeys or ajaxNodeKeys?

            Johan

            • 3. Re: rerender a specific treenode or whole tree?
              Nick Belaevski Master

              Johan,

              Add row key for the desired node to the set of either ajaxKeys or ajaxNodeKeys. Nodes contained that have their keys in ajaxKeys wil be re-rendered together with all children, while nodes that have their keys in ajaxNodeKeys will be re-rendered without children nodes, only the node contents itself.

              • 4. Re: rerender a specific treenode or whole tree?
                Johan Borchers Newbie

                Yes it is working!

                The tree is like this:

                <rich:tree id="tree"
                 value="#{programmeHandler.root}"
                 var="item"
                 nodeFace="#{item.type}"
                 binding="#{programmeHandler.tree}"
                 ajaxSubmitSelection="true"
                 nodeSelectListener="#{programmeHandler.selectNode}"
                 ajaxNodeKeys="#{programmeHandler.renderNodeList}"
                 reRender="detail-panel">
                


                The bean node select listener:
                public void selectNode(NodeSelectedEvent e) {
                 HtmlTree tree = (HtmlTree) e.getComponent();
                 renderNodeList.clear();
                 renderNodeList.add(tree.getRowKey());
                }
                


                The panel with detail fields:
                <a4j:form ajaxSubmit="true" reRender="tree">
                 <rich:panel id="detail-panel">
                


                After mutating e.q. a title of the selected node in the detail fields and submitting it via the a4j:form only the selected node is rerendered and not the whole tree. Very nice!

                Thanks!

                Johan