1 2 Previous Next 23 Replies Latest reply on May 27, 2009 9:08 PM by meghiddo

    Need help with data source to populate nodes of rich:tree

      I know how to populate the nodes using a .properties file. But thsi will not work for my project. I have a web service, where data is stored in this format:

      <measurementProject>
       <projectId>exampleProject1</projectId>
       <name>exampleProject1</name>
       <permissions class="java.util.ArrayList">
       <projectPermission>
       <userId>exampleUser1</userId>
       <permission>admin</permission>
       </projectPermission>
       </permissions>
       <devices class="java.util.ArrayList">
       <projectDevice>
       <deviceId>exampleDevice1</deviceId>
       </projectDevice>
       </devices>
       <channels class="java.util.ArrayList">
       <projectChannel>
       <channelId>exampleChannel3</channelId>
       </projectChannel>
       </channels>
      </measurementProject>
      



      The nodes will be populated using the elements name, projectDevice, and channelId. It is unrealistic for me to transfer all the data to .properties files.

      So is there a method out there to help me easily take the data from those three elements and use it to populate the tree nodes? I already have the method written to deserialize the data, using simplexml. But past that point I am unsure what to do.

      Thanks

        • 1. Re: Need help with data source to populate nodes of rich:tre

          please anyone?

          if it helps here is how I deserialize my data:

          public Device readXML(InputStream xml) throws Exception {
           Serializer serializer = new Persister();
          
           Device device = null;
           device = serializer.read(Device.class, xml);
           xml.close();
           return device;
           }


          • 2. Re: Need help with data source to populate nodes of rich:tre
            nbelaevski

            Hi,

            Either make Device and another classes implement TreeNode/extend TreeNodeImpl or use rich:treeNodesAdaptor/rich:recursiveTreNodesAdaptor.

            • 3. Re: Need help with data source to populate nodes of rich:tre

              Is there anywhere that will give me instructions on how to go about doing your first suggestion?

              Are the nodeAdaptor tags specifically meant for doing what I am trying to do? I had already looked at those but didnt see how it works for my probem.

              Which method would you say will be the easiest?

              • 4. Re: Need help with data source to populate nodes of rich:tre
                nbelaevski

                How does Device class looks like? Have you checked livedemo examples?

                • 5. Re: Need help with data source to populate nodes of rich:tre

                  yes, I have looked at livedemo examples. In teh example it uses a data source that it declares at /WEB-INF/src, however it does not show you waht is included in the src file, so it is kind of difficult to make my data match up with this.

                  This is what I believe you are asking for with my device class:

                  <device>
                   <deviceId>exampleDevice1</deviceId>
                   <name>Example Device 1</name>
                   <property name="longitude">2.222</property>
                   <property name="type">pressure guage</property>
                   <property name="latitude">1.111</property>
                   </device>
                  


                  I forgot that my readXML method actually deserializes my device data, and not the project data, so lets ignor my first thread and I will put this another way.

                  I have an xml layout like the one above for my devices. Then I have the readXMl method to deserialize this data. I need to take this deserialized sata and use it to populate the nodes of my tree. Here is my actual device class as well if it helps:

                  package deviceContainer;
                  
                  import java.util.Map;
                  
                  import org.simpleframework.xml.*;
                  
                  @Root
                  public class Device {
                  
                   @Element(required=false)
                   private String deviceId;
                  
                   @Element(required=false)
                   private String name;
                  
                   @ElementMap(entry = "property", key = "name", attribute = true, inline = true, required=true, data=false, empty=true)
                   private Map<String, String> properties;
                  
                   public String getDeviceId() {
                   return deviceId;
                   }
                  
                   public void setDeviceId(String deviceId) {
                   this.deviceId = deviceId;
                   }
                  
                   public String getName() {
                   return name;
                   }
                  
                   public void setName(String name) {
                   this.name = name;
                   }
                  
                   public Map<String, String> getProperties() {
                   return properties;
                   }
                  
                   public void setProperties(Map<String, String> properties) {
                   this.properties = properties;
                   }
                  
                  }


                  • 6. Re: Need help with data source to populate nodes of rich:tre
                    nbelaevski

                    Great! The idea behind data adaptors is very simple: rich:treeNodesAdaptor allows to declaratively describe tree data levels using EL-expressions. rich:recursiveTreeNodesAdaptor is just a recursive variant of rich:treeNodesAdaptor. So, you'll have to:

                    1. Determine EL expressions for the tree nodes you wish to build
                    2. Build the tree using tree nodes adaptors

                    Some more examples are available here (SVN): http://anonsvn.jboss.org/repos/richfaces/branches/community/3.3.X/samples/treeModelDemo

                    • 7. Re: Need help with data source to populate nodes of rich:tre

                      This is what i wa stalking about with the livedemo example:

                      public class FileSystemBean {
                       private static String SRC_PATH = "/WEB-INF/src";
                      
                       private FileSystemNode[] srcRoots;
                      
                       public synchronized FileSystemNode[] getSourceRoots() {
                       if (srcRoots == null) {
                       srcRoots = new FileSystemNode(SRC_PATH).getNodes();
                       }
                      
                       return srcRoots;
                       }
                      }
                      


                      You can see it has SRC_PATH = "/WEB-INF/src";

                      but there is no way for me to know what the /src looks like.

                      • 8. Re: Need help with data source to populate nodes of rich:tre

                        Well I believe I already have the EL expressions, unless I am mistaken:

                        <rich:tree style="width:300px" switchType="ajax">
                         <rich:recursiveTreeNodesAdaptor roots="#{fileSystemBean.sourceRoots}" var="item" nodes="#{item.nodes}" />
                         </rich:tree>


                        This is the same format used in some of those examples.

                        I just dont know what fileSystemBean.sourceRoots and item.nodes should be refrencing. I have looked through those examples but I seem to be having trouble putting this all together.

                        I feel like I am close, if you could just give me a bit more detail I think I can do this.

                        so the FileSystemBean from the post right above should be where the root nodes for my tree comes from right. My root nodes will all be from the DeviceId element. So it seems to me I need to replace
                        private static String SRC_PATH = "/WEB-INF/src";
                        with something else right? But I do not know what needs to go in there instead of /WEB-INF/src

                        And then my other EL statement is item.nodes, which must be referring to the FileSystemNode class right? But when I lok at that class I do not see at all how it finds the nodes. It is a lot of unfamiliar java code.

                        • 9. Re: Need help with data source to populate nodes of rich:tre
                          nbelaevski

                          FileSystemBean reads structure from file system, you have to understand how it works - it's really easy. It is not suited to read XML files, so copying it as is won't help.

                          Do you have bean property containing collection of root nodes to show in tree?

                          • 10. Re: Need help with data source to populate nodes of rich:tre

                            No I dont, that is exactly what I need but I am no tsure how to write it. That is exactly what I am needign though

                            • 11. Re: Need help with data source to populate nodes of rich:tre

                              Or wait do you mean a .properties file? Because I do know hwo to make that work, but a .properties file is not feasible, because the xml is going to be changing all the time.

                              I know how to popultae the nodes from a .properties file or a node list, because there are examples of each, but I do not know how to write the java code that will take xml elements and use them to populate nodes

                              • 12. Re: Need help with data source to populate nodes of rich:tre

                                come on dont abandon me now lol

                                • 13. Re: Need help with data source to populate nodes of rich:tre

                                  sorry, I was looking at yoru source code and just now sent you an email with the address provided in the code. I didnt realize it was you until I looked at the forum again. I hope this is OK

                                  • 14. Re: Need help with data source to populate nodes of rich:tre
                                    ilya_shaikovsky

                                    we just showing basic creation of Tree Data structure.. Sure the datasources could be different for every application :) And this is out of scope for the RF. We just providing samples of basic model creation and adaptors usage which you could adopt to your data source.

                                    1 2 Previous Next