10 Replies Latest reply on Jun 8, 2009 4:14 PM by meghiddo

    need a bit more help getting tree to work as intended

      I think I am just mis-using some of the elements or attributes. I have looked at tutorials and such but cant seem to figure this one out.
      If I understand correctly what I have read, I can first load a list with some xml. I have gotten to this point. I have a list I call ids. When I do this line:

      System.out.println("Printing out ids list: "+ids.toString());

      it prints out:

      Printing out ids list: [<?xml version="1.0" encoding="UTF-8"?>
      <deviceCollection>
       <device>
       <deviceId>spaces2</deviceId>
       <name>spaces2</name>
       </device>
       <device>
       <deviceId>exampleDevice1</deviceId>
       <name>Example Device 1</name>
       </device>
       <device>
       <deviceId>JSFTEST02</deviceId>
       <name>JSFTEST02</name>
       </device>
      </deviceCollection]


      I cut out some of the values but as you can see, my list "ids" now holds this xml.

      So lets say I want to use deviceId as the roots, and name for the child under each root.

      So using the value of ids I have there, it should come out like this:

      |-spaces2
      |---spaces2
      |
      |-exampleDevice1
      |---Example Device 1
      |
      |-JSFTEST02
      |---JSFTEST02

      Just a simple tree right? So how can I do this?

      Right now I am doing something else. Right now I am loading my ids list with just the deviceId values, so my list when printed as a string looks like:

      printing: [spaces2, exampleDevice1, JSFTEST02]

      Now this is very simple to bind to a tree, but I end up with a tree that has three branches and no child nodes.
      Playing around with that I get various results, but nothing I am looking for.


      So basically, I have a list that is loaded with xml data, and I need to use the deviceId element as the root and the name element as the nodes under the roots.
      I know I have read that this is possible, but I cant figure out how to do this.
      I have seen an example that used var="items" nodes="#{items.nodes}"
      but I cant make any sense of this. I have looked through many tutorials and such and cant seem to get this.

      Please help?

        • 1. Re: need a bit more help getting tree to work as intended

          I was looking at it and it seems something like

          <rich:recursiveTreeNodesAdaptor roots="#{treeBean.ids}" var="item" nodes="item.name" />

          would work, but it just renders a blank space.

          If I just use

          <rich:recursiveTreeNodesAdaptor roots="#{treeBean.ids}" />

          it also is a blank page, so maybe I was wrong about being able to use xml in a java list as the data source?

          • 2. Re: need a bit more help getting tree to work as intended

            I meant of course

            <rich:recursiveTreeNodesAdaptor roots="#{treeBean.ids}" var="item" nodes="#{item.name}" />

            • 3. Re: need a bit more help getting tree to work as intended

              well this doesnt look good...
              worked on this all day with no luck and no replies either

              • 4. Re: need a bit more help getting tree to work as intended

                nothing? so I should take that as I am completely off here?
                I am not even on teh right track then?

                • 5. Re: need a bit more help getting tree to work as intended
                  nbelaevski

                   

                  "Meghiddo" wrote:
                  I meant of course

                  <rich:recursiveTreeNodesAdaptor roots="#{treeBean.ids}" var="item" nodes="#{item.name}" />

                  This should work.

                  • 6. Re: need a bit more help getting tree to work as intended

                    hmm I wonder what the heck Im doing wrong then?

                    • 7. Re: need a bit more help getting tree to work as intended

                      well there were definitely some things I needed to change. But still having problems, can you tell me what this means:

                      I was able to load my list ids with the following value:

                      [<?xml version="1.0" encoding="UTF-8"?>
                      <deviceCollection>
                       <device>
                       <deviceId>exampleDevice1</deviceId>
                       <name>Example Device 1</name>
                       </device>
                       <device>
                       <deviceId>WSN-Module-8F3A-D247-4B99</deviceId>
                       <name>WSN CRio Device</name>
                       </device>
                      </deviceCollection>]


                      Then I bind the list ids to my tree like so:

                      <rich:recursiveTreeNodesAdaptor roots="#{recTreeBean.ids}" />

                      However it gives me a tree with one node, and that node is one very long String that looks like this:

                      <?xml version="1.0" encoding="UTF-8"?> exampleDevice1 Example Device 1 WSN-Module-8F3A-D247-4B99 WSN CRio Device

                      So it seems that I am definitely getting the data into my ids variable, but it is not being recognized as xml, but just converting this xml into one long string.

                      Am I correct on that? So before I add this data to my ids list, I need to parse it so it is recognized as xml right? Is that what I am needing to do or am I still off?

                      I use simpleXml for my parsing and such, but I am still learning how to use it.

                      So if Im right I need to use simplexml to parse this data into xml, then put that xml into the ids list, right?

                      If someone can help me do this it would be great, but also if someone can just confirn that this is what needs to be done it would be nice too

                      • 8. Re: need a bit more help getting tree to work as intended

                        Ok I looked at it and I was getting my responseBody as a String, not a s astream, so that is why it was doing that.

                        So here is where I am.

                        I have an InputStream that is holding my xml. I cant add this to a list because a list will not accept an inputStream.

                        So I need to get this InputStream into some useable form which I can bind to the tree.

                        ANy sugestions?

                        • 9. Re: need a bit more help getting tree to work as intended

                          maybe this?

                          private TreeNode data;
                          ....
                          FacesContext context = FacesContext.getCurrentInstance();
                           try {
                           data = XmlTreeDataBuilder.build(new InputSource(responseBody));
                           } catch (SAXException e) {
                           // TODO Auto-generated catch block
                           e.printStackTrace();
                           } catch (IOException e) {
                           // TODO Auto-generated catch block
                           e.printStackTrace();
                           }


                          and that should set the TreeNode data. I mean i already know that responseBody is a stream that is holding my xml, so this should bind that to data right?



                          • 10. Re: need a bit more help getting tree to work as intended

                            bah of course not.
                            no that just gives me a one branch tree with this branch:
                            org.richfaces.model.TreeNodeImpl@e391c4

                            any sugestions of how to fix this>

                            I think it comes down to that i have a stream or string or whatever else I can convert it to that is holding my xml data. But it does not recognize it as xml.