1 2 Previous Next 15 Replies Latest reply on May 26, 2010 3:46 PM by alexroz

    Problems with NodeSelectedEvent

    ashsneider
      Hi everyone.

      I am using a Rich Tree component and have a problem handling the rich tree NodeSelectedEvent.

      I need to get the selected node id or name. But I get an exception handling the event:

      java.lang.ClassCastException: org.richfaces.component.html.HtmlTree cannot be cast to org.richfaces.component.html.HtmlTree

      Here is my listener:
      -------------------------------------------------------
      @Name("treelistener")
      @Scope(ScopeType.EVENT)
      public class TreeListener implements NodeSelectedListener{

           public void processSelection(NodeSelectedEvent event)
                     throws AbortProcessingException {
                
                HtmlTree tree = (HtmlTree)event.getComponent();
                     
           }

      }
      ---------------------------------------------------------

      Here is my Tree class:
      ------------------------------------------------------
      @Name("treebean")
      @Scope(ScopeType.SESSION)
      public class TreeBean {
           

           private List<Category> categoryList;

           private TreeNode categoryTree = new TreeNodeImpl();
                
           private String nodeTitle;
           
           @Logger Log log;
           
      /*...*/     
           @Create
           public void createTree() {
                
                categoryList = new CategoryList().getResultList();          
                
                try {
                     sort(categoryList);
                     addChildren();
                } catch(Exception e) {
                     log.error("Error creating the category tree.", e.getMessage());
                }
                                                        
           }          
           
           
              
           public String getNodeTitle() {
                return nodeTitle;
           }
                                                       
           public TreeNode getCategoryTree() {
                return categoryTree;
           }

           public void setCategoryTree(TreeNode categoryTree) {
                this.categoryTree = categoryTree;
           }
      ------------------------------------------------------

      Here is my page:
      ------------------------------------------------------
      <h:form>
                                                   <rich:tree value="#{treebean.categoryTree}"
                                                        var="node" icon="" iconLeaf="" nodeSelectListener="#{treelistener.processSelection}"
                                                        ajaxSubmitSelection="true" >
                                                        <rich:treeNode>
                                                             <h:outputText value="#{node}"/>
                                                        </rich:treeNode>                    
                                                   </rich:tree>                    
                                              </h:form>

      ------------------------------------------------------

      I suppose it is some sort of a classpath problem. I have added the libraries to my ear content and to the manifest.

      I desperately need an answer.

      Thank you in advance.
        • 1. Re: Problems with NodeSelectedEvent
          sbasinge
          I've had success with:

          import org.richfaces.component.UITree;
          ....
          UITree tree = (UITree) event.getComponent();
          • 2. Re: Problems with NodeSelectedEvent
            ashsneider

            Yes, i've tried that one too. It didn't work. Where did you import your libraries, and which richfaces version did you use?


            Thanks.

            • 3. Re: Problems with NodeSelectedEvent
              sbasinge

              I have richfaces3.2.1GA in my web-inf/lib.

              • 4. Re: Problems with NodeSelectedEvent
                lxhung

                Do you success with NodeSelecttedEvent. I use richfaces 3.2.2GA but it still not work.(even with UITree).
                Do you give some advice?

                • 5. Re: Problems with NodeSelectedEvent
                  wzawirski

                  I have the same problem.


                  [lifecycle] /home.xhtml @46,76 nodeSelectListener="#{personManager2.processSelection}": javax.ejb.EJBTransactionRolledbackException: 
                  org.richfaces.component.html.HtmlTree cannot be cast to org.richfaces.component.html.HtmlTree
                  





                  public void processSelection(NodeSelectedEvent event){
                     
                   HtmlTree tree = (HtmlTree)event.getComponent();
                  
                     ................
                  }




                  Line


                  HtmlTree tree = (HtmlTree)event.getComponent();



                  causes problem.
                  How to resolve that problem?

                  • 6. Re: Problems with NodeSelectedEvent

                    I have the same problem, and i'm using richfaces 3.2.2 GA


                    any idea?

                    • 7. Re: Problems with NodeSelectedEvent
                      joblini

                      The following works for me.  The only thing is that I haven't figured out when it gets called.  I'm not sure what exactly is meant by selected?  Is it the node with the rectangle outline?  Because it is not called when I click on a node, it seems to be called (sometimes) when I collapse or expand a node 


                      import org.richfaces.component.html.HtmlTree;
                      
                      @Name("treeController")
                      @Scope(ScopeType.CONVERSATION)
                      public class TreeController { 
                      
                          public void onNodeSelected(NodeSelectedEvent event) throws AbortProcessingException {
                              HtmlTree tree = (HtmlTree)event.getComponent();
                          }
                      }
                      



                      <rich:tree nodeSelectListener="#{treeController.onNodeSelected}"



                      • 8. Re: Problems with NodeSelectedEvent
                        julianwki

                        Hi!


                        Do you use the NodeSelectedListener with a fixed or with a dynamic tree? I have problems fire a NodeSelected-event if I dynamically build my tree with a rich:recursiveTreeNodeAdaptor. It simply doesn't work. A test tree with fixed entries works fine by the way.


                        Any suggestions?


                        TIA, Julian

                        • 9. Re: Problems with NodeSelectedEvent
                          joblini

                          I am using recursiveTreeNodeAdaptor

                          • 10. Re: Problems with NodeSelectedEvent
                            julianwki

                            Yes, me too. But the rather more interesting question is if you can dynamically (that should mean 'by run time') change the content of the tree and still be able to use your routine?

                            • 11. Re: Problems with NodeSelectedEvent
                              julianwki

                              Julian Wiersbitzki wrote on Jan 01, 2009 14:02:


                              Yes, me too. But the rather more interesting question is if you can dynamically (that should mean 'by run time') change the content of the tree and still be able to use your routine?


                              Happy new year by the way. ;-)

                              • 12. Re: Problems with NodeSelectedEvent
                                staticr

                                I am also having this issue, but with the changeExpandListener.  I think that I have tracked the problem down to the class loader. The code:


                                log.info(evt.getSource().getClass().getClassLoader().toString());
                                log.info(HtmlTree.class.getClassLoader().toString());
                                


                                is giving me two different class loaders.  Maybe you are having a similar issue.


                                Cheers,
                                  Colin

                                • 13. Re: Problems with NodeSelectedEvent

                                  I believe this problem stems from the seam webloader. We changed this setting and the problem went away.


                                  Edit the file



                                  jboss-4.2.2.GA\server\default\deploy\jboss-web.deployer\META-INF\jboss-service.xml





                                  Make sure the Atribute UseJBossWebLoader is set to true:


                                  <attribute name="UseJBossWebLoader">true</attribute>






                                  Hope this helps!

                                  • 14. Re: Problems with NodeSelectedEvent
                                    francisco.affonso


                                    Joran Kikke wrote on Jun 04, 2009 13:02:


                                    Make sure the Atribute UseJBossWebLoader is set to true:


                                    <attribute name="UseJBossWebLoader">true</attribute>





                                    reallyyy thanks for the tip!!! I spend about 4 hours working around a ClassCastException caused by the class loader config.

                                    1 2 Previous Next