3 Replies Latest reply on Dec 19, 2009 9:03 AM by Matthias Nott

    Problem with tree:nodeSelectListener

    David Bolsover Newbie

      I'm having a problem setting a NodeSelectListener on a dynamically built HtmlTree.

      Heres my code:
      JSF:

      <rich:panel style="width: 900px">
       <h:form>
       <h:panelGrid columns="5">
       <rich:tree binding="#{NavigationListBean.tree1}" ></rich:tree>
       <%-- other trees --%>
       </h:panelGrid>
       </h:form>
      </rich:panel>


      JAVA:
      public HtmlTree getTree1() {
       return buildTree(1);
       }
      
       private HtmlTree buildTree(int menuNo) {
       HtmlTree tree = new HtmlTree();
       NavigationDao dao = new NavigationDao();
       Navigation top = dao.retrieveActiveTopLevelNavigationsBySeq(menuNo);
       TreeNodeImpl rootNode = new TreeNodeImpl();
      
       tree.setAjaxKeys(null);
       tree.setAjaxSubmitSelection(true);
       tree.setSwitchType("client");
       tree.setPreserveModel("true");
       tree.setStyle("width:150px");
      
       MethodBinding binding =
       AppUtils.getCurrentApplication().createMethodBinding("#{NavigationListBean.processSelection}",
       new Class[] { NodeSelectedEvent.class });
      
       tree.setNodeSelectListener(binding);
       rootNode.setData(top.getSeq());
      
       TreeNodeImpl childNode = new TreeNodeImpl();
      
       childNode.setData(top.getMenu());
       rootNode.addChild(top, childNode);
      
       List<Navigation> treeNavigations = dao.retrieveActiveNavigationsByParentMenu(top.getMenu());
      
       walkTree(childNode, treeNavigations);
       tree.setValue(rootNode);
      
       return tree;
       }
      
       private void walkTree(TreeNode parentNode, List<Navigation> treeNavigations) {
       NavigationDao dao = new NavigationDao();
       TreeNodeImpl childNode;
      
       for (Navigation nav : treeNavigations) {
       childNode = new TreeNodeImpl();
       childNode.setData(nav.getMenu());
       parentNode.addChild(nav, childNode);
      
       List<Navigation> childNavigations = dao.retrieveActiveNavigationsByParentMenu(nav.getMenu());
      
       walkTree(childNode, childNavigations);
       }
       }
      
       public void processSelection(NodeSelectedEvent event) {
       // this method never called
      
       HtmlTree tree = (HtmlTree) event.getComponent();
       Navigation selectedNavigation = (Navigation) tree.getRowData();
      
       System.out.println(selectedNavigation.toString());
       }


      The trees are displayed on page just fine - but the processSelection(NodeSelectedEvent) is never called -- any help please?



        • 1. Re: Problem with tree:nodeSelectListener
          Matthias Nott Newbie

          Did you ever get an answer? It works fine for me in JBoss, but in Tomcat 5.5, it doesn't fire the method.

           

          Thanks!

           

          M

          • 2. Re: Problem with tree:nodeSelectListener
            David Bolsover Newbie

            Hi Matthias

             

            I did not get a solution via the forum - but I did solve the problem...

             

            The problem and solution lies in the lines:

             

            rootNode.addChild(top, childNode);
            and

            parentNode.addChild(nav, childNode);

            where the objects top and nav in my code were instances of a POJO: Navigation.

             

            The method signature is:

            public void addChild(Object o, TreeNode<T> tn)

             

            However, it appears that setting any moderately complex Object o will cause problems (at least in Tomcat which is my deployment environment)

             

            In this situation now, I use code like rootNode.addChild(""+counter++, childNode); where int counter is initialzed to 0 outside the recursive loop.

             

            Having got a solution I never investigated the problem further - but it would be nice to know what the problem really is.

             

            David

            • 3. Re: Problem with tree:nodeSelectListener
              Matthias Nott Newbie

              Thanks for sharing your solution. I had a much more simple problem: I had set <h:form prependId="false"> for historic reasons, and that was why the whole thing broke. Removing the prependId="false" solved this problem.

               

              Tnx,

              M