1 2 Previous Next 20 Replies Latest reply on Jul 10, 2009 12:52 PM by meghiddo

    Need help deciding on data type for rich:tree and how to imp

      There is one main question here, and then others that are followups depending on the answer to this, so I will ask the big question first -

      Is it possible to use Collections that are loaded with java Objects rather than String variables to bind to my rich:tree? I know I can bind a List loaded with String values to my tree and have it display, but can I use a List that is loaded with java Objects and have it also display a tree somehow?

      If you don't understand what I am trying to ask just read on

      I have been looking at various things, and so far all I have been able to get to display a tree is a List full of String values.

      Now if I load this List with the actual java Object itself, including all the variables within that Object of course, where the tree should be is a blank space. There may be a problem with how I am doing my rich:tree tag attributes and such so my first question is - if I have a List loaded with java Objects, and those Objects have two String variables - name and device, is there a way to bind this List to a rich:tree, and have it use the name String variable as the root and the device String variable as the nodes under each root? I have tried many variations but there are just so many different ways to try this I figured it would be better to ask here and hope someone answers.

      And, if that is not possible, I was also looking at the TreeNodeImple data type. Now in the examples I have seen it uses String values like this:

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



      but is it possible to replace String with my Project Object and still have that work (like I have been trying to do with List), like this:

      private TreeNodeImpl<Project> stationNodes = new TreeNodeImpl<Project>();


      And if so, then the same question I had for the List data type, how can I bind this to the rich:tree correctly so it uses the name String variable from Project as the root and the device String variable as the node?

      But all this hinges on the question, is it possible to use Collections loaded with Objects rather than Strings as the variable I bind to the rich:tree?

        • 1. Re: Need help deciding on data type for rich:tree and how to

          here is an idea of how I have been trying to bind this stuff to my jsf page (projectTreeNode is a TreeNodeImpl data type):

          <rich:tree value="#{nodesBean.projectTreeNode}" var="project">
           <rich:recursiveTreeNodesAdaptor roots="#{project.name}" nodes="#{project.device}" />
           </rich:tree>


          • 2. Re: Need help deciding on data type for rich:tree and how to
            nbelaevski

             

            "Meghiddo" wrote:
            Is it possible to use Collections that are loaded with java Objects rather than String variables to bind to my rich:tree?

            Yes. That's the main purpose of tree node adaptor tags (rich:treeNodesAdaptor and rich:recursiveTreeNodesAdaptor).

            • 3. Re: Need help deciding on data type for rich:tree and how to

              OK, good, because I can get it this far with no problem.

              Let's say I have an object that has two variables, projectName and deviceName. I need to use projectName for the top level of the tree and the deviceName under each projectName as the nodes.

              What Collection would you suggest, I have it in a List right now so I can just leave it that way easily.

              My problem I guess then is how I am trying to bind this list to the rich:tree tag. An example of one of my attempts is above.

              Can you give me an idea of what the jsf should look like to achieve this?

              • 4. Re: Need help deciding on data type for rich:tree and how to

                Hmm now that I think about it I may not be calling the method that loads the list first. I may need to use @PostConstruct above my loadNodes() method.

                That may be what I have been missing the entire time.

                But still, if you have an example of a List loaded with Objects, and how the jsf rich:tree tags should look when using them it would be great.

                I will look back through the livedemo and dev guide stuff and try to find an example myself too, but if you could direct me there faster it would help (This has to be done by Friday ) or an actual example using the two variables I gave you in the above post would be outstanding

                • 5. Re: Need help deciding on data type for rich:tree and how to

                  should be something like this from what I can tell but I cant get anything from this:

                  <rich:tree>
                   <rich:recursiveTreeNodesAdaptor roots="#{nodesBean.projectTreeNode}" var="project" nodes="#{project.projectName}" />
                   </rich:tree>


                  • 6. Re: Need help deciding on data type for rich:tree and how to

                    When i try that though it always takes a while, but project from the nodes attribute gets underlined and says "project cannot be resolved"

                    Any idea why this is happening or what I can do about it?

                    • 7. Re: Need help deciding on data type for rich:tree and how to

                      actually now this is showing a tree, although not what i want. this code:

                      <rich:tree>
                       <rich:recursiveTreeNodesAdaptor roots="#{nodesBean.projectNameList}" var="project" nodes="#{project.name}" />
                       </rich:tree>


                      is showing a tree, however for each node it has something representing the java object, not the projectName. Then when I try to expand the tree node it tells me something about not being able to find the value for project.name

                      • 8. Re: Need help deciding on data type for rich:tree and how to

                        Im getting very close now, I just need a bit of guidance. I have two different things that give me trees but not exactly what Im looking for. This is the first:

                        <rich:tree>
                         <rich:recursiveTreeNodesAdaptor roots="#{nodesBean.projectNameList}" var="project" >
                         <rich:treeNodesAdaptor nodes="#{project.name}" />
                         </rich:recursiveTreeNodesAdaptor>
                         </rich:tree>


                        Now that gives me a tree that has the Object representations as the roots and then when you expand the nodes you see the actual project name. The tree looks like this:

                        -projectContainer.MeasurementProject@46a09b
                        --Project Test 005
                        -projectContainer.MeasurementProject@6f19d5
                        --Project Test 06

                        etc

                        or I have this displaying another tree that isnt exactly what I need:

                        <rich:tree>
                         <rich:recursiveTreeNodesAdaptor roots="#{nodesBean.projectNameList}" var="project" >
                         <rich:treeNode value="#{project.name}" >
                         <h:outputText value="#{project.name}" />
                         </rich:treeNode>
                         </rich:recursiveTreeNodesAdaptor>
                         </rich:tree>


                        ow this display a tree where the project Names are the first thing you see, but there are no nodes to expand, it is just a list of the projects. I have tried a few things like adding another rich:treeNode or another h:outputText, but I can't seem to get it any further.

                        So which one is on the right track and how can I fix it lol? Ill keep trying myself, but would love for someone to help me a,long here


                        • 9. Re: Need help deciding on data type for rich:tree and how to

                          I can get the projectName to display with the devices under it, but the Project Object is still the top level node. Anyone tell me how I should change this code?

                          <rich:tree>
                           <rich:recursiveTreeNodesAdaptor roots="#{nodesBean.projectNameList}" var="project">
                           <rich:treeNodesAdaptor nodes="#{project.name}">
                           <rich:treeNodesAdaptor nodes="#{project.deviceName}" />
                           </rich:treeNodesAdaptor>
                           </rich:recursiveTreeNodesAdaptor>
                           </rich:tree>


                          it gives me a tree like this:

                          -projectContainer.MeasurementProject@46a09b
                          --Project Test 005
                          ----Device 05
                          -projectContainer.MeasurementProject@6f19d5
                          --Project Test 06
                          ----Device 06

                          So I pretty much have it if I could just move everything one level up and get rid of the actual Object String representation as the topmost node

                          • 10. Re: Need help deciding on data type for rich:tree and how to
                            nbelaevski

                            Add rich:treeNode component into the top rich:recursiveTreeNodesAdaptor. BTW, it will work if you use rich:treeNodesAdaptor instead of rich:recursiveTreeNodesAdaptor.

                            • 11. Re: Need help deciding on data type for rich:tree and how to

                              Hmm Im doing somethign wrong with your advice, can you tell me what I am missing?

                              I tried this:

                              <rich:tree>
                               <rich:treeNodesAdaptor roots="#{nodesBean.projectNameList}" var="project">
                               <rich:treeNodesAdaptor nodes="#{project.projectId}">
                               <rich:treeNodesAdaptor nodes="#{project.name}" />
                               </rich:treeNodesAdaptor>
                               </rich:treeNodesAdaptor>
                               </rich:tree>


                              And this:

                              <rich:tree>
                               <rich:treeNode>
                               <rich:treeNodesAdaptor roots="#{nodesBean.projectNameList}" var="project">
                               <rich:treeNodesAdaptor nodes="#{project.projectId}">
                               <rich:treeNodesAdaptor nodes="#{project.name}" />
                               </rich:treeNodesAdaptor>
                               </rich:treeNodesAdaptor>
                               </rich:treeNode>
                               </rich:tree>


                              and I got a blank space from both, no tree displays at all

                              • 12. Re: Need help deciding on data type for rich:tree and how to

                                yeah the only thing that will give me a tree is if I use recursiveTreeNodesAdaptor, Im not sure why. All that this object has are two String variables.

                                The closest I have been able to get is with this code:

                                <rich:tree>
                                 <rich:recursiveTreeNodesAdaptor roots="#{nodesBean.projectNameList}" var="project">
                                 <rich:treeNode>
                                 <h:outputText value="#{project.projectId}" />
                                 <rich:treeNode>
                                 <h:outputText value="#{project.name}" />
                                 </rich:treeNode>
                                 </rich:treeNode>
                                 </rich:recursiveTreeNodesAdaptor>
                                 </rich:tree>


                                This give me a tree that you cant expand or collapse, but all the projects are listed under their projectIds. Closer but still cant be used

                                • 13. Re: Need help deciding on data type for rich:tree and how to

                                  The following worked although it seems very odd syntax:

                                  <rich:tree>
                                   <rich:treeNodesAdaptor nodes="#{nodesBean.projectNameList}" var="project">
                                   <rich:treeNodesAdaptor nodes="#{project.name}" />
                                   <rich:treeNode>
                                   <h:commandLink value="#{project.projectId}" />
                                   </rich:treeNode>
                                   </rich:treeNodesAdaptor>
                                   </rich:tree>


                                  That uses the ID as the root node and the projectName as the child under each root. It seems like it would be the other way around, can anyone explain why this is? From the way I have it there it seems like the name would be the root node and the ID would be the child under each root. I want it the way it is now, but when I first did this I had projectId and name swicthed, because I thought it would work in the reverse order.

                                  Either way looks like I have it now. The next step is going to be to replace the name String value with a devices List value, which Im sure will give me more issues lol.

                                  C'est la vie

                                  • 14. Re: Need help deciding on data type for rich:tree and how to

                                    actually even though the display is correct now, I dont think this will work...

                                    I need to be able to control what clicking on a node does, and how will I be able to do so for

                                    <rich:treeNodesAdaptor nodes="#{project.name}" />
                                    ?

                                    I know I can do it for
                                    <rich:treeNode>
                                     <h:commandLink value="#{project.projectId}" />
                                     </rich:treeNode>
                                    but how will I do so for the name which is in the treeNodesAdaptor tag?

                                    1 2 Previous Next