8 Replies Latest reply on Oct 15, 2010 9:28 AM by ahoehma

    Load Data from database into Rich:tree(Very Very Urgent)

    a.pradhan9049

      Hi All,


      I am not able to load data from database into rich:tree.This is my biggest  for me chanllange now a days.

      MY requirment is to load rich:tree with data from database. I want to Show multilevel rich:tree  like this 

      Gobal

          Asiapacific

                      India

                           Karnatak

                           Orisaa

                  China

                  Pakistan 

        North America

        Europ

       

      Please Help me out rgarding this.(URGENT)

       

       

      Thanks you ALL.

        • 1. Re: Load Data from database into Rich:tree(Very Very Urgent)
          sarocks

          Hi Ashutosh,

           

          A nice example in the richfaces live demo page is here:

          default tree model:

          http://livedemo.exadel.com/richfaces-demo/richfaces/tree.jsf?tab=model&cid=124709

           

           

          Don't bother about nodeSelectListener in that example. In the example data loaded from a file.

          I hope you can do this way.

           

          All the best.

           

          -Saroj

          • 2. Re: Load Data from database into Rich:tree(Very Very Urgent)
            a.pradhan9049

            Thank you saroj.The propsed  example shows ,How to load data into rich:tree from *.properties file, But not from Database. I need to load data from databse.

            Gobal

                Asiapacific

                            India

                                 Karnatak

                                 Orisaa

                        China

                        Pakistan 

              North America

              Europ

             

            I need to load the data in this strcture from Database. Please Help me to solve this isssue.Thank you again Saroj

             

             

            Thnaks

            Ashutosh

            • 3. Re: Load Data from database into Rich:tree(Very Very Urgent)
              sarocks

              Hi Ashutosh,

               

              You should be able to create Arraylists of String using the data from the database. Different Arraylists should be created for different nodes.

              And as in example, you should able to add nodes to the parent nodes in for loop.

               

              For example,

              parent arraylist - Asiapacific, North America, Europ

              child arraylist - India, China, Pakistan

              subchild arraylist - ...

               

              then in for loop, add Asiaspecific node to Global, then add nodes India, China, Pakistan to the parent node (Asiaspecific).

               

              I hope you got it!

              Sorry for my bad english.

               

              Thanks,

              Saroj

              • 4. Re: Load Data from database into Rich:tree(Very Very Urgent)
                ahoehma

                Hi Ashutosh,

                 

                I would do this:

                 

                1. Create a Domainmodel for the Data

                 

                    Continent

                       --> a Name

                       --> have 0 .. n Land

                                             --> a Name

                                             --> have 0 .. m City

                                                                    --> a Name

                 

                    Continent.getLands() -> List<Land>

                    Land.getCities() -> List<City>

                    Continent.getName()

                    ...

                 

                2. Create a JPA Layer for the Domainmodel (via Annotations)

                 

                    @Entity, @OneToMany, ...

                 

                    Store/Load via JPA

                 

                3. Display the Data via rich:tree

                 

                  <rich:tree>

                      <rich:recursiveTreeNodesAdaptor var="continent" nodes="#{earth.continents}">

                          <rich:treeNode>
                             <h:outputText value="#{continent.name}"/>
                           </rich:treeNode>

                 

                          <rich:recursiveTreeNodesAdaptor var="land" nodes="#{continent.lands}">
                             <rich:treeNode>
                                <h:outputText value="#{land.name}"/>
                             </rich:treeNode>

                 

                             <rich:recursiveTreeNodesAdaptor var="city" nodes="#{land.cities}">
                                <rich:treeNode>
                                  <h:outputText value="#{city.name}"/>
                                </rich:treeNode>
                              </rich:recursiveTreeNodesAdaptor>

                            </rich:recursiveTreeNodesAdaptor>

                 

                     </rich:recursiveTreeNodesAdaptor>

                 

                  </rich:tree>

                 

                 

                Regards

                Andreas

                -[http://www.ahoehma.de]-

                • 5. Re: Load Data from database into Rich:tree(Very Very Urgent)
                  a.pradhan9049

                  Hi,Andreas ,

                   

                        Thank you very much.But I  am not able to understand  Domainmodel part. Could you please elaborate a bit about  point no1 and point no2.

                       It will be great,  If you could preapare a model like the below and show the steps

                   

                  Gobal

                      Asiapacific

                                  India

                                       Karnatak

                                       Orisaa

                              China

                              Pakistan 

                    North America

                    Europ

                   

                   

                  Thanks ,

                  Ashutosh

                  • 6. Re: Load Data from database into Rich:tree(Very Very Urgent)
                    a.pradhan9049

                    Hi Saroj,

                     

                    Thank you for quick response and solution.But one thing i want to understand from you i:e If   i want to show the 10 level tree then i have to create 10 ArrayList   and to get the data from DB we have to write 10 menthods as one method   will return one arraylist at a time. So will it be acceptable  Please  suggest me .

                     

                    Thnaks,

                    Ashutosh

                    • 7. Re: Load Data from database into Rich:tree(Very Very Urgent)
                      sarocks

                      Hi again,

                       

                      I think 10 arraylist is fare enough for the purpose!

                      As per your example different lists should exist for continent,country,states,city, etc.

                       

                      i think you can create some logic in a method to put the arraylist data in the corresponding list. If you explain how the database list is generated, i can propose some way to do it.

                       

                      Thanks,

                      Saroj

                      • 8. Re: Load Data from database into Rich:tree(Very Very Urgent)
                        ahoehma

                        Hi Ashutosh Pradhan,

                         

                        please think about "model" and "data" ... you post a example of "data" ... for this data you can create a "model" (OOP, objects, relations ...)

                         

                        Gobal

                           Asiapacific                  -> Continent

                                    India                          -> Land

                                         Karnatak                    -> City

                                         Orisaa                        -> City

                                    China                         -> Land

                                    Pakistan                     -> Land

                          North America              -> Continent

                          Europ                            > Continent

                         

                        for JPA please read here.

                         

                        Regards

                        Andreas

                        -=[http://www.ahoehma.de]=-