6 Replies Latest reply on Jun 7, 2013 6:39 PM by bleathem

    problems selecting a node of a tree from code

    agallo73

      Hello I have a tree using a TreeModelRecursiveAdaptor and I want to select a particular node depending on some text to be entered identifying a node in the tree.

       

      I noticed that unfortunatelly there's no tree direct method to perform this action.

       

      There's a selection attribute which wants a collection of org.richfaces.model.SequenceRowKey to perform a proper selection.

       

      The problem is : how to construct these SequenceRowKey sequence?

       

      I added a listener to my code to understand what is created behind the scenes when a selection is performed and i saw that the framework creates an array of  DeclarativeModelKey objects, one for each descending node of the tree (starting from top) and  each having a modelID and a modelKey.

       

      The modelKey depends on the position of the node within the children' list and so might be computed while I am not able to understand how to get the modelID.

       

      I am wondering whether there's a method to perform a selection from code when using a tree with treemodelrecursiveadaptor or someone should create all the sequence looking for information somewhere that might not be available (see the modelID for instance).

       

      Is there an intelligent way to perform a selection once it's known the node to be selected or not?

       

      Any help is greatly appreciated.

       

      Thanks in advance.

       

      Antonio

        • 1. Re: problems selecting a node of a tree from code
          bleathem

          You could try using the compnentControl component to select a tree node using the javascript API of the tree.

          • 2. Re: problems selecting a node of a tree from code
            agallo73

            Sorry but how can i do it from javascript if I need to perform a search from the bean on the tree and then select the node that meet search criteria? Is there some way to access th tree model and get the modelId i mentioned in my post? Otherwise is there some way to define a  criteria for SequenceRowKey (rowKeyConverter or something else..)  ? I am using a TreeModelRecursiveAdaptor and I have to populate the selection attribute with a collection of these objects. The problem is that these objects are strictly related to the framework's internals and so I can not immagine how could be possible to provide these SequenceRowKey in a correct way and do not understand why you provide these ways of selecting nodes without any direct method in the UITree component. I also tried to acces the TreeModel but this method is protected in the UITree class... nor the TreeModelRecursiveAdaptor gives me any info as far as my problem

             

            Coming back to my case,

             

            I saw that when selecting a node, the framework creates an array of  DeclarativeModelKey objects, one for each descending node of the tree (starting from top) and  each having a modelID and a modelKey.

             

            Can you please tell me if it's possible to get the modelId in some way of these objects or show me some examples on how to use selection in a tree with a TreemodelrecursiveAdaptor?

             

            Thanks in advance.

            • 3. Re: problems selecting a node of a tree from code
              lfryc

              This converter implementation might help you find a way:

              https://github.com/richfaces/richfaces/blob/5.0.0.Alpha1/framework/src/main/java/org/richfaces/convert/DeclarativeModelSequenceKeyConverter.java#L88

               

              I assume you could achieve what you want by using rowKeyConverter and selection attribute.

              • 4. Re: problems selecting a node of a tree from code
                lfryc

                Would be actually nice to find this way and provide it as a sample in Showcase or at least components-demo.

                 

                Btw this might be simpler to achieve with tree first and tren try declarative model.

                 

                If you want a sandbox to play with, here it is:

                https://github.com/richfaces/richfaces/blob/master/examples/components-demo/src/main/webapp/examples/iteration/tree.xhtml#L176

                • 5. Re: problems selecting a node of a tree from code
                  agallo73

                  I solved the problem using my previous approach based on a sequence of DeclarativeModelKey objects.

                  I retrieved  the modelID using a binding to the TREEModelRecursiveAdaptor  and also calculated the key of each DeclarativeModelKey object, putting some logic in the bean class  in order to keep track of each  node position within the parent's children' list, each time it's added to the tree.  

                  I also clearly used a selection attribute in the xhtml in order to point to the collection of SequenceRowKey objects.

                  • 6. Re: problems selecting a node of a tree from code
                    bleathem

                    Antonio, that's great!  This seems like a common use case.  How would you feel about submitting a github pull request with a dev-example demonstrating your solution?  Also, if you can suggest any API improvements that would facilitate this use case, please file a feature request in jira detailing such improvements.