1 Reply Latest reply on Jul 15, 2008 5:52 AM by Kerdudou Ronan

    Dynamic tree loading...

    Szczepan Marchewka Newbie

      Hi !

      I want to build in my app dynamic tree with "lazy loading" (dynamic loading subnodes on expand of the parent node). Data for the tree must be loaded from the database and it must be loaded dynamically because of many, many data in the database.

      It must be done in that way:
      0. In the tree I must have only 3 level of nodes
      1. In my backing bean I declare model and load only 1-level nodes.
      2. On expand 1-level node I load 2-level subnodes of the clicked 1-level node.
      3. On expand 2-level node I load 3-level subnodes of the clicked 2-level node.
      4. If the subnodes of the 1-level and 2-level nodes are already loaded then expanding ignore loading from the database

      How to do this?
      Should I use default TreeNodeImpl or implement custom one?
      Should I use TreeNodesAdaptor?

      I seeked on the forum and documentation, but find any examples and my experiments give no results.

      Please help.

      Regards

      SM

        • 1. Re: Dynamic tree loading...
          Kerdudou Ronan Apprentice

          we are using a List of BeanNode for first level and each BeanNode contains a List BeanNode (childs)...
          each BeanNode also contains an object corresponding to our database element and some params like 'selected' 'loaded' 'expended'...
          we're using rich:tree with rich:treeNodeAdaptator and rich:recursiveTreeNodeAdaptator ...
          and we have a class:
          public class ArbreAdapterHandler implements TreeStateAdvisor, NodeExpandedListener, NodeSelectedListener {

          and we configure rich tree with params like thoses (depending on the tree) :
          stateAdvisor="#{arbreAdapter}"
          changeExpandListener="#{arbreAdapter.processExpansion}"
          ajaxSubmitSelection="true"
          nodeSelectListener="#{arbreAdapter.processSelection}"
          adviseNodeOpened="#{arbreAdapter.adviseNodeOpened}"
          adviseNodeSelected="#{arbreAdapter.adviseNodeSelected}"

          and finally we're able to do what you described...

          this is the first phase of this dev, we're now making an interface TreeLoader for functions loadRoot() and loadChilds(BeanNode) getAdapter()...
          to make an handler instanciate the ArbreAdapterHandler... it'll be more generic to be able to use it with different structures. in the handler : new ArbreAdapter(this) and the the adapter uses fuctions of the handler to load data...
          #{arbreAdapter... -> #{handler.arbreAdapter...

          (note Arbre=Tree)