0 Replies Latest reply on Apr 13, 2015 8:13 AM by omid pourhadi

    rich:changeExpandListener does not apply to children

    omid pourhadi Apprentice

      Hi,

       

      I created a rich tree with changeExpandListener. it runs only at root level of my tree and does not apply to children that are being added by the listener dynamically .

      what should I do ?

       

      here is my code

       

      <rich:tree id="programTree"
                      ajaxKeys="#{_item.id}"
                       switchType="ajax"
                      value="#{programTreeList.treeNode}" var="_item">
                      <rich:changeExpandListener type="com.test.ui.TreeNodeXpander"/>              
                      <rich:treeNode >
                          <h:outputText value="#{_item.programName}" />
                     </rich:treeNode>
      </rich:tree>
      
      
      

       

      public class TreeNodeXpander implements NodeExpandedListener
      {
      
        
          @Override
          public void processExpansion(NodeExpandedEvent nodeExpandedEvent) throws AbortProcessingException
          {      
              Object source = nodeExpandedEvent.getSource();
              if (source instanceof HtmlTree)
              {
                  HtmlTree tree = (HtmlTree) source;          
                  Object rowKey = tree.getRowKey();
                  TreeNode modelTreeNode = tree.getModelTreeNode(rowKey);
                  Program rowData = (Program) tree.getRowData(rowKey);
                  List<Program> list = fetchChildren(rowData, modelTreeNode);
                  if (CollectionUtil.isNotEmpty(list))
                  {
                      for (Program program : list)
                      {
                          TreeNodeImpl<Program> tp = new TreeNodeImpl<Program>();
                          tp.setData(program);
                          modelTreeNode.addChild(program.getId(), tp);//won't expand 
                      }
                  }
      
              }
      
          }
      
      
      

       

      PS : I am trying to create a partial(lazy) loading tree.