4 Replies Latest reply on Feb 26, 2010 9:18 AM by meex

    rich:tree root node

      Hi community,

       

      I use the recursiveTreeNodesAdaptor to build my model, now I have the requirement, that the root node should not show up in the hierarchie, is there a possibility with this adaptor?

      Now it looks like this

      old_hier.gif

      ...and it should look like this

      new_hier.gif

       

      regards

      Markus

        • 1. Re: rich:tree root node
          nbelaevski

          Hi Markus,

           

          Yes, this is possible. Please post your code.

          • 2. Re: rich:tree root node

            Thanx for your response, here's my code:

             

            XHTML ...

             

            <rich:tree id="tree" style="width:350px" status="globalStatus"

            adviseNodeSelected="#{masterDataController.adviseNodeSelected}"

            adviseNodeOpened="#{masterDataController.adviseNodeOpened}"

            binding="#{masterDataBean.tree}"

            componentState="#{masterDataBean.dataState}"

            nodeSelectListener="#{masterDataController.processSelection}"

            reRender="accountstring, tab1, tab2, tab3, tabpanel, sendform:emails"

            ajaxSubmitSelection="true" switchType="client" ajaxKeys="#{null}">

            <rich:recursiveTreeNodesAdaptor roots="#{masterDataController.model}"

            var="node" nodes="#{node.children}">

            <rich:treeNode>

            <h:outputText style="#{node.style}" value="#{node}"></h:outputText>

            </rich:treeNode>

            </rich:recursiveTreeNodesAdaptor>

            </rich:tree>

             

            ... and the java part

             

            /**

            * Build the accounts tree recursively

            *

            * @param isRoot

            * @param account

            * @return

            */

            private AccountsTreeNode buildTree(Accounts account) {

            AccountsTreeNode node = new AccountsTreeNode(account, masterDataBean

            .getAuthorization(account.getSicCode()));

            // select childs

            List<Accounts> accounts = accountsDAO.findByParent(account.getId());

            // recursion

            for (Accounts _account : accounts) {

            node.getChildren().add(buildTree(_account));

            }

            return node;

            }

             

            public AccountsTreeNode getModel() {

            if (masterDataBean.getModel() == null) {

            // root

                AccountsTreeNode root = new AccountsTreeNode();

                Set<String> rootCoSePars = new HashSet<String>();

                for(String cosepar : masterDataBean.getCosepars()) {

                Accounts rootAccount = serviceLayer.getSqlExecutorService().getRootAccount(cosepar);

                if(rootAccount==null || Helper.isEmpty(rootAccount.getSicCode())) continue;

                if(!rootCoSePars.contains(rootAccount.getSicCode())) {

                rootCoSePars.add(rootAccount.getSicCode());

                AccountsTreeNode node = buildTree(rootAccount);

                root.getChildren().add(node);

                }

                }

            masterDataBean.setModel(root);

            }

            // verify that there's a root account

            return masterDataBean.getModel();

            }

             

            public class AccountsTreeNode implements Serializable {

            private static final long serialVersionUID = 6636782030870561876L;

            private final Accounts account;

            private final boolean authorized;

            private List<AccountsTreeNode> children = new ArrayList<AccountsTreeNode>();

             

            public AccountsTreeNode() {

            this.account = null;

            this.authorized = false;

            }

             

            public AccountsTreeNode(Accounts account, boolean authorized) {

            this.account = account;

            this.authorized = authorized;

            }

             

            public String getStyle() {

            if(authorized) return "color: green;";

            return Constants.EMPTY;

            }

             

            public List<AccountsTreeNode> getChildren() {

            return children;

            }

             

            public void setChildren(List<AccountsTreeNode> children) {

            this.children = children;

            }

             

            public Accounts getAccount() {

            return this.account;

            }

             

            public boolean isAuthorized() {

            return this.authorized;

            }

             

            @Override

            public String toString() {

            if(account==null) return Constants.EMPTY;

            return account.toString();

            }

            }

             

            Markus

            • 3. Re: rich:tree root node
              nbelaevski

              Hi Markus,

               

              You don't need to create special AccountsTreeNode class to use tree adaptors, as they work with lists directly. You should specify collection of items as value of "roots" expression, not single node.

              • 4. Re: rich:tree root node

                Worked perfectly, thanx and regards

                 

                Markus