3 Replies Latest reply on Nov 25, 2011 8:42 AM by Lydia Ares

    RF 4: Expand tree programmatically

    Lydia Ares Newbie

      Hi,

       

      I'm building a tree programmatically extending TreeNodeImpl, which works fine so far.

      The thing is that I want to display the tree totally expanded, but the Richfaces tree is collapsed by default.

      I use switchType ajax.

       

      Is there any client side javascript function that I could call on page load? Or could I achieve the same already server-side?

      Thanks for any advice..

        • 1. Re: RF 4: Expand tree programmatically
          Karsten Wutzke Expert

          This works for me:

          {code}<rich:treeNode expanded="#{true}" ...>{code}

          Karsten

          1 of 1 people found this helpful
          • 2. Re: RF 4: Expand tree programmatically
            Brian Leathem Master

            Indeed, using the expanded attribute seems like the only way to achieve this.  Looking through the TreeNodeImpl javadoc, the expanded state is indeed not exposed.  Neither is it available via the javascript API.  You could fire events to expand the treeNodes, but that's getting messy.

             

            If you would like to see a better programmatic API for toggling tree nodes, please file a feature request jira, and we'll take a closer look at it.

            1 of 1 people found this helpful
            • 3. Re: RF 4: Expand tree programmatically
              Lydia Ares Newbie

              Thanks for the hints you gave, Karsten and Brian.

              I didn't know that the "expanded" attribute in treeNode can take an EL expression (since it's not documented).

              What I also found out that the EL expression needs to reference a property with getter and setter - and, toggle type being ajax, on toggling the nodes the setter is called!

               

              So this is my solution:

              I map the expanded attribute to a "expanded" property in my custom node class (extends TreeNodeImpl) with initial value "true".

              So Richfaces can keep track of the expanded/collapsed state even without defining a treeToggleListener..