3 Replies Latest reply on Jul 11, 2009 7:57 PM by meghiddo

    Advice on data type for java Object pertaining to rich:tree

      I have a tree that is layed out this way:

      -project 1
      ---device 1
      ------channel 1-1
      ------channel 1-2
      ---device 2
      ------channel 2-1
      ---device 3
      -project2
      --etc
      ------etc

      I have this working right now as far as the project name and the device List. I have an object(ProjectHolder) with a String variable projectName; and a List variable devicesList;. I can get a tree out of it that shows my projects, and the devices that belong to each underneath it.

      Here is the code for the tree:

       <rich:tree>
       <rich:treeNodesAdaptor nodes="#{nodesBean.projects}" var="project">
       <rich:treeNode>
       <h:outputText value="#{project.projectName}" />
       </rich:treeNode>
       <rich:recursiveTreeNodesAdaptor roots="#{project.devicesList}" var="device">
       <rich:treeNode>
       <h:outputText value="#{device}" />
       </rich:treeNode>
       </rich:recursiveTreeNodesAdaptor>
       </rich:treeNodesAdaptor>
       </rich:tree>


      Now I need to do the channels as well. I was planning to do it the same way i did devices, by making a channelsList, and then including it within the devicesList node there.

      But now I realize this will give me a tree that has the project with the correct devices listed, but under each device it is going to list every single channel from each device under each device (contained within the project). So my tree would end up this way if I am correct:


      -project 1
      ---device 1
      ------channel 1-1
      ------channel 1-2
      ------channel 2-1
      ---device 2
      ------channel 1-1
      ------channel 1-2
      ------channel 2-1
      ---device 3

      I need to figure out what data type to use that will show ownership between devices and channels, and that will still work when I try to iterate through it within the tree.

      I was thinking of using Map<Device, String>
      but I don't know if this will work with the tree the way I want it to or not. So can anyone suggest the best way to do this? At first I thought I could quickly do it just following the same format I did for projects and devices, but I don't think that is going to work.

      All I need is a suggestion for how my ProjectHolder Object should change.

      In other words instead of using:

      String projectName;
      List devicesList;
      List channelsList;

      I should use:

      String projectName;
      ????


        • 1. Re: Advice on data type for java Object pertaining to rich:t

          Hmm maybe I should ask it this way..

          What would be acceptable to use on a rich:tree...

          Map<Object, String> - with the Object as the parent node and the String values listed below it

          or

          List<String, List> - with the first String as the top node and the next List as children under them

          or

          Map<String, String> - with the first String as the upper node and the second String as the nodes below the first String

          Are any of those acceptable? Will they still act in the way I need them to when I bind them as an Object to my tree?

          • 2. Re: Advice on data type for java Object pertaining to rich:t

            Actually looking at it that second one is the only one that would work for what I need.

            So, is I include in my Object a

            List<String, List<String>>


            Will I be able to control its behavior in the tree like I need it to?

            I will need the first List item to be a top node, and each item in the inner list to appear beneath it, and so on. These will all be child nodes to a String value btw.

            -project
            ---devices
            ------channels

            • 3. Re: Advice on data type for java Object pertaining to rich:t

              please lol