1 Reply Latest reply on Nov 24, 2011 5:26 PM by jsoye

    RF 4.1-M4 Programmatically set Tree node

    jsoye

      Hi,

      I have a <rich:tree> and I'm able to allow the user to reorder it, i.e. if I have the following tree,

       

      myTree

            +-----eee

            +-----aaa

            +-----bbb             <--- hightlighted because user selected it

       

      the user can select node 'bbb' and move it above 'aaa' by clicking on a 'promote' button. Although it works, the node that's

      highlighted remains in the same position, i.e. where 'bbb' was - the 3rd position in this example,

       

      myTree

            +-----eee

            +-----bbb

            +-----aaa              <-----this is highlighted after user hits the 'promote' button

       

      Is there a way to programmatically select (highlight) the node? I've tried using "setRowKey" and "setSelection" (methods of UITree)

      but nothing happens, e.g.

       

      Integer sortOrder = myNode.getSortOrder();

      SequenceRowKey srk = new SequenceRowKey("root","S"+ (sortOrder.intValue()-1) );

      ...

      tree.setRowKey(srk);

       

      Collection<Object> collection = new ArrayList<Object>();

      collection.add(srk);

       

      tree.setSelection(collection);

       

      I'm only guessing at this code, as it seems like the reverse of the TreeSelectionChanged code in the showcase. Am I on the right track

      (i.e. are either of these the correct method to use) or am I heading towards Mars?

       

      Thanks :-)

        • 1. Re: RF 4.1-M4 Programmatically set Tree node
          jsoye

          Oops. I missed spotting the "selection" attribute in <rich:tree>. This was the answer. Just point it at the collection, i.e.

           

          <rich:tree id="myTree" ... selection="#{treeBean.treeSelection}">

          </rich:tree>

           

          @Stateful

          @Named

          @ConversationScoped

          public class TreeBean implements java.io.Serializable {

           

          private Collection<Object> treeSelection = new ArrayList<Object>();  // plus getters & setters

          ...

           

               public void promoteNode() {

                    Integer sortOrder = myNode.getSortOrder();

                    SequenceRowKey srk = new SequenceRowKey("root","S"+ (sortOrder.intValue()-1) );

                    ...

           

                    Collection<Object> collection = new ArrayList<Object>();

                    collection.add(srk);

                    setTreeSelection(collection);

               }

           

           

          }