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

    rich:tree root node

    Markus Reich Newbie

      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


      ...and it should look like this





        • 1. Re: rich:tree root node
          Nick Belaevski Master

          Hi Markus,


          Yes, this is possible. Please post your code.

          • 2. Re: rich:tree root node
            Markus Reich Newbie

            Thanx for your response, here's my code:


            XHTML ...


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






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

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

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

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


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





            ... 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


            // select childs

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

            // recursion

            for (Accounts _account : accounts) {



            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())) {


                AccountsTreeNode node = buildTree(rootAccount);






            // 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;




            public String toString() {

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

            return account.toString();





            • 3. Re: rich:tree root node
              Nick Belaevski Master

              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
                Markus Reich Newbie

                Worked perfectly, thanx and regards