7 Replies Latest reply on Jan 8, 2011 2:49 AM by Ilya Sorokoumov

    Anyone can give an example to use rich:tree in RF 4.0?

    Hoveran Gao Newbie

      I am trying to use rich:tree in RichFaces 4.0, but existing examples are for 3.3, some classes like TreeNodeImpl is already deleted in 4.0, anyone can give an example on how to write the bean class for rich:tree in RF4.0?

       

      Thanks a lot!

        • 1. Anyone can give an example to use rich:tree in RF 4.0?
          Jay Balunas Master

          Hi Hoveran,

           

          You can take a look here for now : http://anonsvn.jboss.org/repos/richfaces/trunk/examples/richfaces-showcase/src/main/webapp/richfaces/

           

          To see it in action you can build the showcase example and deploy to a local server.  Tree is not fully documented yet in our component guide ( but is planned ).

           

          Regards,

          -Jay

          • 2. Anyone can give an example to use rich:tree in RF 4.0?
            Hoveran Gao Newbie

            Hi Jay,

             

            I visit the link, and find the using of rich:tree, but I can't find the codes in RF 4.0 to implement following Bean:

             

            treeBean.rootNodes

             

            Where can I find the codes of TreeBean for 4.0?

             

            Thanks again,

            Hoveran

            • 4. Anyone can give an example to use rich:tree in RF 4.0?
              Hoveran Gao Newbie

              Hi Jay,

               

              I can't find org.richfaces.event.TreeSelectionChangeEvent in my using JAR, any place I can find one to take it?

               

              Thanks,

              Hoveran

              • 5. Anyone can give an example to use rich:tree in RF 4.0?
                Ilya Sorokoumov Master

                I found org.richfaces.event.TreeSelectionEvent; in M4. May be it was renamed in M5 because if you look at this link:

                http://anonsvn.jboss.org/repos/richfaces/trunk/ui/iteration/api/src/main/java/org/richfaces/event/ you can't find there TreeSelectionEvent but only TreeSelectionChangeEvent.

                • 6. Anyone can give an example to use rich:tree in RF 4.0?
                  Hoveran Gao Newbie

                  Thanks for reply!

                   

                  I am trying the richfaces*-4.0.0.20101110-M4.jar, there is no TreeSelectionChangeEvent as example listed. I struggled several days on RichFaces rich:tree in M4, still failed. Not sure anyone has one successful example which can be shared..

                   

                  Thanks,

                  Hoveran

                  • 7. Anyone can give an example to use rich:tree in RF 4.0?
                    Ilya Sorokoumov Master

                    See what I found in M4 show case app(But it seems that M4 app didn't have an implemeted selectionListener so that I'm afraid it may be not working at all in M4 ):

                     

                    XHTML:

                     

                    <rich:tree id="tree" nodeType="#{node.type}" var="node"

                                        value="#{treeBean.rootNodes}" toggleType="client">

                                        <rich:treeNode type="country">

                                                            #{node.name}

                                                  </rich:treeNode>

                                        <rich:treeNode type="company" icon="/images/tree/disc.gif">

                                                            #{node.name}

                                                  </rich:treeNode>

                                        <rich:treeNode type="cd" icon="/images/tree/song.gif">

                                                            #{node.artist} - #{node.title} - #{node.year}

                                                  </rich:treeNode>

                              </rich:tree>

                     

                    JAVA Class:

                     

                    package org.richfaces.demo.tree;

                     

                     

                    import java.io.Serializable;

                    import java.util.ArrayList;

                    import java.util.HashMap;

                    import java.util.List;

                    import java.util.Map;

                     

                     

                    import javax.annotation.PostConstruct;

                    import javax.faces.bean.ApplicationScoped;

                    import javax.faces.bean.ManagedBean;

                    import javax.faces.bean.ManagedProperty;

                    import javax.swing.tree.TreeNode;

                     

                     

                    import org.richfaces.demo.tree.model.CD;

                    import org.richfaces.demo.tree.model.Company;

                    import org.richfaces.demo.tree.model.Country;

                    import org.richfaces.event.TreeSelectionEvent;

                     

                     

                    /**

                    * @author Ilya Shaikovsky

                    *

                    */

                    @ManagedBean

                    @ApplicationScoped

                    public class TreeBean implements Serializable {

                        @ManagedProperty(value = "#{cdsParser.cdsList}")

                        private List<CDXmlDescriptor> cdXmlDescriptors;

                        private List<TreeNode> rootNodes = new ArrayList<TreeNode>();

                        private Map<String, Country> countriesCache = new HashMap<String, Country>();

                        private Map<String, Company> companiesCache = new HashMap<String, Company>();

                     

                     

                        @PostConstruct

                        public void init() {

                            for (CDXmlDescriptor current : cdXmlDescriptors) {

                                String countryName = current.getCountry();

                                String companyName = current.getCompany();

                                Country country = getCountryByName(current);

                                Company company = getCompanyByName(current, country);

                                CD cd = new CD(current.getTitle(), current.getArtist(), company, current.getPrice(), current.getYear());

                                company.getCds().add(cd);

                            }

                        }

                     

                     

                        private Country getCountryByName(CDXmlDescriptor descriptor) {

                            String countryName = descriptor.getCountry();

                            Country country = countriesCache.get(countryName);

                            if (country == null) {

                                country = new Country();

                                country.setName(countryName);

                                countriesCache.put(countryName, country);

                                rootNodes.add(country);

                            }

                            return country;

                        }

                     

                     

                        private Company getCompanyByName(CDXmlDescriptor descriptor, Country country) {

                            String companyName = descriptor.getCompany();

                            Company company = companiesCache.get(companyName);

                            if (company == null) {

                                company = new Company();

                                company.setName(companyName);

                                company.setParent(country);

                                country.getCompanies().add(company);

                                companiesCache.put(companyName, company);

                            }

                            return company;

                        }

                     

                     

                        private void selectionListener(TreeSelectionEvent event) {

                            //TODO: implement when ready

                        }

                     

                     

                        public List<CDXmlDescriptor> getCdXmlDescriptors() {

                            return cdXmlDescriptors;

                        }

                     

                     

                        public void setCdXmlDescriptors(List<CDXmlDescriptor> cdXmlDescriptors) {

                            this.cdXmlDescriptors = cdXmlDescriptors;

                        }

                     

                     

                        public List<TreeNode> getRootNodes() {

                            return rootNodes;

                        }

                     

                     

                        public void setRootNodes(List<TreeNode> rootNodes) {

                            this.rootNodes = rootNodes;

                        }

                     

                     

                    }