2 Replies Latest reply on May 21, 2010 10:41 AM by ajaykumar kadiyala

    Rich Tree with last node should be check box

    ajaykumar kadiyala Novice

      HI All,

       

      Please help.....

      1) I have requiment that administrator can able to create a user roles at most 3 levels only.

      2) I need to capture the values which is selected.

       

      HI All,


      I am able to consturct a tree structer,pleas help me with a code.


      MeunsTree.xhtml

       

      <h:form>

       

      <rich:tree value="#{myTree.menusRoot1}" var="menus">

       

      <rich:treeNode>

       

      <h:selectManyCheckbox /> //Even if it not  adding a check box to able

       

      <h:outputText value="#{menus}" />

       

      </rich:treeNode>

       

      </rich:tree>


      </h:form>


      MyTree.java


      public class MyTree {

      private TreeNodeImpl<String> menusRoot1 = new TreeNodeImpl<String>();

      private TreeNodeImpl<String> menus1 = new TreeNodeImpl<String>();

      private TreeNodeImpl<String> menus2 = new TreeNodeImpl<String>();

      private TreeNodeImpl<String> menus3 = new TreeNodeImpl<String>();

      private TreeNodeImpl<String> menusItems1 = new TreeNodeImpl<String>();

      private TreeNodeImpl<String> menusItems2 = new TreeNodeImpl<String>();

      private TreeNodeImpl<String> menusItems3 = new TreeNodeImpl<String>();

      private TreeNodeImpl<String> menusItems4 = new TreeNodeImpl<String>();

      private TreeNodeImpl<String> menusItems5 = new TreeNodeImpl<String>();

      private TreeNodeImpl<String> menusItems6 = new TreeNodeImpl<String>();

      private TreeNodeImpl<String> menusItems7 = new TreeNodeImpl<String>();

      private TreeNodeImpl<String> menusItems8 = new TreeNodeImpl<String>();


      private TreeNodeImpl<String> menusItemsAction1 = new TreeNodeImpl<String>();

      private TreeNodeImpl<String> menusItemsAction2 = new TreeNodeImpl<String>();

      private TreeNodeImpl<String> menusItemsAction3 = new TreeNodeImpl<String>();

      private TreeNodeImpl<String> menusItemsAction4 = new TreeNodeImpl<String>();

      private TreeNodeImpl<String> menusItemsAction5 = new TreeNodeImpl<String>();

      private TreeNodeImpl<String> menusItemsAction6 = new TreeNodeImpl<String>();


      private String[] kickRadioFeed = { "Hall & Oates - Kiss On My List",

      "David Bowie - Let's Dance", "Lyn Collins - Think (About It)",

      "Kim Carnes - Bette Davis Eyes",

      "KC & the Sunshine Band - Give It Up" };


      public MyTree() {


      menusItems1.addChild(0, menusItemsAction1);

      menusItems1.addChild(1, menusItemsAction2);

      menusItems1.addChild(2, menusItemsAction3);

      menusItems1.addChild(3, menusItemsAction4);

      menusItems1.addChild(4, menusItemsAction5);

      menusItems1.addChild(5, menusItemsAction6);


      menusItems2.addChild(0, menusItemsAction1);

      menusItems2.addChild(1, menusItemsAction2);

      menusItems2.addChild(2, menusItemsAction3);

      menusItems2.addChild(3, menusItemsAction4);

      menusItems2.addChild(4, menusItemsAction5);

      menusItems2.addChild(5, menusItemsAction6);


      menusItems3.addChild(0, menusItemsAction1);

      menusItems3.addChild(1, menusItemsAction2);

      menusItems3.addChild(2, menusItemsAction3);

      menusItems3.addChild(3, menusItemsAction4);

      menusItems3.addChild(4, menusItemsAction5);

      menusItems3.addChild(5, menusItemsAction6);


      menusItems4.addChild(0, menusItemsAction1);

      menusItems4.addChild(1, menusItemsAction2);

      menusItems4.addChild(2, menusItemsAction3);

      menusItems4.addChild(3, menusItemsAction4);

      menusItems4.addChild(4, menusItemsAction5);

      menusItems4.addChild(5, menusItemsAction6);


      menusItems5.addChild(0, menusItemsAction1);

      menusItems5.addChild(1, menusItemsAction2);

      menusItems5.addChild(2, menusItemsAction3);

      menusItems5.addChild(3, menusItemsAction4);

      menusItems5.addChild(4, menusItemsAction5);

      menusItems5.addChild(5, menusItemsAction6);


      menusItems6.addChild(0, menusItemsAction1);

      menusItems6.addChild(1, menusItemsAction2);

      menusItems6.addChild(2, menusItemsAction3);

      menusItems6.addChild(3, menusItemsAction4);

      menusItems6.addChild(4, menusItemsAction5);

      menusItems6.addChild(5, menusItemsAction6);


      menusItems7.addChild(0, menusItemsAction1);

      menusItems7.addChild(1, menusItemsAction2);

      menusItems7.addChild(2, menusItemsAction3);

      menusItems7.addChild(3, menusItemsAction4);

      menusItems7.addChild(4, menusItemsAction5);

      menusItems7.addChild(5, menusItemsAction6);

      menusItems8.addChild(0, menusItemsAction1);

      menusItems8.addChild(1, menusItemsAction2);

      menusItems8.addChild(2, menusItemsAction3);

      menusItems8.addChild(3, menusItemsAction4);

      menusItems8.addChild(4, menusItemsAction5);

      menusItems8.addChild(5, menusItemsAction6);


      menusItemsAction1.setData("New");

      menusItemsAction2.setData("View");

      menusItemsAction3.setData("Modify");

      menusItemsAction4.setData("Save");

      menusItemsAction5.setData("Cancel");

      menusItemsAction6.setData("Delete");


      menus1.setData("Administration");

      menus2.setData("ShipmentDashboard");

      menus3.setData("DeviceManagement");


      menusRoot1.addChild(0, menus1);

      menusRoot1.addChild(1, menus2);

      menusRoot1.addChild(2, menus3);

      menusItems1.setData("UserRoles");

      menusItems2.setData("UserProfile");

      menus1.addChild(0, menusItems1);

      menus1.addChild(1, menusItems2);

      menusItems3.setData("Shipment Track");

      menusItems4.setData("Track Details");

      menus2.addChild(0, menusItems3);

      menus2.addChild(1, menusItems4);

      menusItems5.setData("Units");

      menusItems6.setData("Sensor");

      menusItems7.setData("Device Model");

      menusItems8.setData("Device Registration");


      menus3.addChild(0, menusItems5);

      menus3.addChild(1, menusItems6);

      menus3.addChild(2, menusItems7);

      menus3.addChild(3, menusItems8);

      }

      //getter and setters

      }
      Need Tree structure menus with a check box

        • 1. Re: Rich Tree with last node should be check box
          Ilya Shaikovsky Master

          Currently you defined only one node and not  defined nodeface. in this case that single node - will represent the same markup for all kind of nodes at all levels. If you need checkboxes only at third level - read about how to defines nodes of different types.

           

          2) I need to capture the values which is selected.

          just map the values of select to model values.

           

           

          please checkout rf-demo sources http://jboss.org/richfaces/demos and explore our samples.

          • 2. Re: Rich Tree with last node should be check box
            ajaykumar kadiyala Novice

            HI Ilya Shaikovsky,

             

            Thanks for your support , I tryed (with this first level,if it's works then I will look another level).

             

            We have a critical delivery, I need your supports.Since we have big issue ,it's cause so many problem and impact project.

             

            As per you suggestion I had done. but there is no values print into brower. please help me.

             

             

             

             

            <rich:tree style="width:300px" value="#{myTreeLibrary.data}" var="item" nodeFace="#{item.type}">

             

                      <rich:treeNode type="menuItemsActions" iconLeaf="/images/tree/singer.gif" icon="/images/tree/singer.gif">

                                <h:outputText value=

            "#{item.name}" /> <br/>

                      </rich:treeNode> 

             

             

            </rich:tree>

             

            ----------MyTreeLibrary.java------------

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

            public

             

             

            class MyTreeLibrary implements

            TreeNode {

             

            Map

             

            menuItemsActions = null

            ;

             

             

             

            public

            MyTreeLibrary() {

             

            }

             

             

             

            private

            Map getMenuItemsActions() {

             

            initData();

             

             

             

            return this.menuItemsActions

            ;

            }

             

             

             

            public void

            initData() {

             

             

             

            menuItemsActions = new

            HashMap();

            MenuItemsActions[] menuitems =

             

            new

            MenuItemsActions[3];

            menuitems[0] =

             

            new

            MenuItemsActions();

             

            menuitems[1] =

             

            new

            MenuItemsActions();

            menuitems[2] =

             

            new

            MenuItemsActions();

            menuitems[0].setName(

             

            "New"

            );

            menuitems[1].setName(

             

            "View"

            );

            menuitems[2].setName(

             

            "Modify"

            );

             

             

             

            this

            .addChild(0, menuitems[0]);

             

             

            this

            .addChild(1, menuitems[1]);

             

             

            this

            .addChild(2, menuitems[2]);

             

             

            menuItemsActions.put(0, menuitems[0]);

             

            menuItemsActions.put(1, menuitems[1]);

             

            menuItemsActions.put(2, menuitems[2]);

            }

             

             

            public void addMenuItemsActions(MenuItemsActions mia) {

             

            }

             

             

            @Override

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

             

            public void

            addChild(Object arg0, TreeNode arg1) {

             

             

            // TODO

            Auto-generated method stub

             

            }

             

             

             

            @Override

             

             

            public

            TreeNode getChild(Object arg0) {

             

             

            // TODO

            Auto-generated method stub

             

             

            return

            (TreeNode) getMenuItemsActions().get(arg0);

            }

             

             

             

            @Override

             

             

            public

            Iterator getChildren() {

             

             

            // TODO

            Auto-generated method stub

             

             

            return

            getMenuItemsActions().entrySet().iterator();

            }

             

             

             

            @Override

             

             

            public

            Object getData() {

             

             

            // TODO

            Auto-generated method stub

             

             

            return this

            ;

            }

             

             

             

            @Override

             

             

            public

            TreeNode getParent() {

             

             

            // TODO

            Auto-generated method stub

             

             

            return null

            ;

            }

             

             

             

            @Override

             

             

            public boolean

            isLeaf() {

             

             

            // TODO

            Auto-generated method stub

             

             

            return

            getMenuItemsActions().isEmpty();

            }

             

             

             

            @Override

             

             

            public void

            removeChild(Object arg0) {

             

             

            // TODO

            Auto-generated method stub

            getMenuItemsActions().get(arg0);

            }

             

             

             

            @Override

             

             

            public void

            setData(Object arg0) {

             

             

            // TODO

            Auto-generated method stub

             

            }

             

             

             

            @Override

             

             

            public void

            setParent(TreeNode arg0) {

             

             

            // TODO

            Auto-generated method stub

             

            }

             

             

             

            public

            String getType() {

             

             

            return "myTreeLibrary"

            ;

             

            }

            }

             

             

            -------------------MenuItemsActions.java----------

             

            public

             

             

            class MenuItemsActions implements TreeNode {

             

             

            private long id;

             

            private String name;

             

            private MyTreeLibrary myTreeLib=null;

             

            @Override

             

            public void addChild(Object arg0, TreeNode arg1) {

             

            throw new UnsupportedOperationException(" do not have children");

             

            }

             

             

            @Override

             

            public TreeNode getChild(Object arg0) {

             

            throw new UnsupportedOperationException("actions do not have children");

             

            }

             

             

            @Override

             

            public Iterator getChildren() {

             

            // TODO Auto-generated method stub

             

            return new ArrayList().iterator();

            }

             

             

            @Override

             

            public Object getData() {

             

            // TODO Auto-generated method stub

             

            return this;

            }

             

             

            @Override

             

            public TreeNode getParent() {

             

            // TODO Auto-generated method stub

             

            return myTreeLib;

            }

             

             

            @Override

             

            public boolean isLeaf() {

             

            // TODO Auto-generated method stub

             

            return true;

            }

             

             

            @Override

             

            public void removeChild(Object arg0) {

             

            throw new UnsupportedOperationException("actions do not have children");

             

            }

             

             

            @Override

             

            public void setData(Object arg0) {

             

            // TODO Auto-generated method stub

             

            }

             

             

            @Override

             

            public void setParent(TreeNode arg0) {

             

             

            this.myTreeLib=(MyTreeLibrary)arg0;

             

            // TODO Auto-generated method stub

             

            }

             

            public String getType() {

             

            return "menuItemsActions";

            }

             

             

            public long getId() {

             

            return id;

            }

             

             

            public void setId(long id) {

             

            this.id = id;

            }

             

             

            public String getName() {

             

            return name;

            }

             

             

            public void setName(String name) {

             

            this.name = name;

            }

             

             

            public MyTreeLibrary getMyTreeLib() {

             

            return myTreeLib;

            }

             

             

            public void setMyTreeLib(MyTreeLibrary myTreeLib) {

             

            this.myTreeLib = myTreeLib;

            }

            }