5 Replies Latest reply on Sep 27, 2008 8:08 PM by smith123

    conversation problem with tree

    milesif

      Hi everybody,

      I deployed my application as a .war in jboss 4.2.1.

      I would like to have a tree bound to a conversation to have the tree model saved in the conversation so that:
      1. queries are not repeated each time I expand/collapse a node already expanded/collapsed by calling @OneToMany properties of the entities beans used by my tree model
      2. when I select a node a method of a bean within the same conversation is called.
      Now each ajax interaction gets a new conversation and I would like to have only one.

      My page is

      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       xmlns:s="http://jboss.com/products/seam/taglib"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:rich="http://richfaces.org/rich"
       template="../../layout/template.xhtml">
      
      <ui:define name="body">
      
       <rich:panel>
       <div style="width: 300px;height: 300px; overflow: scroll;">
       <h:form>
      
      
       <rich:tree switchType="ajax" nodeSelectListener="#{geoStructureTreeManager.processSelection}"
       ajaxSubmitSelection="true" ajaxSingle="true" ignoreDupResponses="true" reRender="sel"
       binding="#{geoStructureTreeManager.tree}" >
       <rich:treeNodesAdaptor id="country" nodes="#{geoStructureTreeManager.rootNodes}" var="country">
       <rich:treeNode>
       <h:commandLink action="#{geoStructureTreeManager.click}" value="#{country.name}" />
       </rich:treeNode>
      
       <rich:recursiveTreeNodesAdaptor id="geographicStructureAdaptor" roots="#{country.geographicStructures}"
       nodes="#{geographicStructure.childrenList}" var="geographicStructure">
       <rich:treeNode >
       <h:outputText value="#{geographicStructure.name} #{conversation.id}" />
       </rich:treeNode>
      
       </rich:recursiveTreeNodesAdaptor>
      
       </rich:treeNodesAdaptor>
       </rich:tree>
       </h:form>
       </div>
       <h:outputText id="sel" value="#{geoStructureTreeManager.name}" />
      
       </rich:panel>
      
      </ui:define>
      </ui:composition>
      


      and my bean

      @Scope(ScopeType.CONVERSATION)
      @Name("geoStructureTreeManager")
      public class GeoStructureTreeManager {
      
       @In
       protected FacesMessages facesMessages;
      
       @In
       private EntityManager entityManager;
      
       private HtmlTree tree;
      
       private TreeState treeState;
      
       @DataModel
       private List<Country> rootNodes;
      
      
       public String click() {
       System.out.println("bombolame");
       return "";
       }
      
       public void processSelection(NodeSelectedEvent event) {
       System.out.println("SELECTED");
       UITree tree = (UITree) event.getComponent();
       System.out.println(tree);
       GeographicStructure geoStructure = (GeographicStructure) tree.getRowData();
       System.out.println(geoStructure.getName());
       name = geoStructure.getName();
       System.out.println("Conversation=" + Conversation.instance().getId());
       }
      
       public List<Country> getRootNodes() {
       if(rootNodes == null) {
       Query qry = entityManager.createQuery("from Country c order by c.name");
       rootNodes = qry.getResultList();
       }
       return rootNodes;
       }
      
      
      
       private String name = "";
      
      
       public String getName() {
       return name;
       }
      
       public void setName(String name) {
       this.name = name;
       }
      
       public HtmlTree getTree() {
       if(tree == null)
       tree = new HtmlTree();
       return tree;
       }
      
       public void setTree(HtmlTree tree) {
       this.tree = tree;
       }
      
       public TreeState getTreeState() {
       return treeState;
       }
      
       public void setTreeState(TreeState treeState) {
       this.treeState = treeState;
       }
      
      }
      


      when I expand a root node I get the following error (the binding seems not to work because the conversation is not found).

      11:45:53,493 WARN [lifecycle] executePhase(RESTORE_VIEW 1,com.sun.faces.context.FacesContextImpl@1be496b) threw exception
      javax.el.PropertyNotFoundException: /protected/geo/geo_structure_tree.xhtml @24,48 binding="#{geoStructureTreeManager.tree}": Target Unreachable, identifier 'geoStructureTreeManager' resolved to null
       at com.sun.facelets.el.TagValueExpression.setValue(TagValueExpression.java:95)
       at com.sun.faces.lifecycle.RestoreViewPhase.doPerComponentActions(RestoreViewPhase.java:244)
      


      I tried to inject the tree in the conversation as suggested in http://www.jboss.com/index.html?module=bb&op=viewtopic&t=116956: I have no more errors but nothing happens.

      I also tried to use componentState as suggested by http://www.jboss.com/index.html?module=bb&op=viewtopic&t=119410, but it did not work either: there are no errors but when I try to expand a node,it does not expand.

      What I would like to do is to have a conversation to edit my tree adding, modifying and deleting its nodes.

      I do not understand what's going on.
      Any idea, please? What should I do to keep my tree model in the conversation and call the same conversation when selecting a different node?


      Thanks in advance for your help and I apologize for the long post.......

      ciao FRancesco


        • 1. Re: conversation problem with tree
          milesif

          Update ;-)

          Now my tree looks like this

           <rich:tree switchType="ajax" componentState="#{geoStructureTreeManager.treeState}">
           <rich:recursiveTreeNodesAdaptor id="geoStructure"
           roots="#{geoStructureTreeManager.rootNodes}"
           nodes="#{geoStructure.childrenList}"
           var="geoStructure">
           <rich:treeNode>
           <h:outputText value="#{geoStructure.name}" />
           </rich:treeNode>
           </rich:recursiveTreeNodesAdaptor>
           </rich:tree>
          


          Now it works (even if I do not know why...). It lives in the its conversation and queries are executed only when a node is expanded (I checked it sniffing the conversation id with CVOnversation.instance().getId()). The only notable difference I am aware of with respect to the previous version is that now my tree has only one recursiveTreeNodesAdaptor instead of a recursiveTreeNodesAdaptor nested in a treeNodesAdaptor.

          I have only one problem left that I really do not understand: when I bind my tree to the tree property of the geoStructureTreeManager bean and I try to expand one of the root nodes soon after having loaded them, I get this error:
          17:29:48,174 INFO [STDOUT] org.richfaces.component.html.HtmlTree@8e683a SET TREE->2
          17:29:51,430 WARN [lifecycle] executePhase(RESTORE_VIEW 1,com.sun.faces.context.FacesContextImpl@1b21ae2) threw exception
          javax.el.PropertyNotFoundException: /protected/geo/geo_structure_tree.xhtml @23,57 binding="#{geoStructureTreeManager.tree1}": Target Unreachable, identifier 'geoStructureTreeManager' resolved to null
           at com.sun.facelets.el.TagValueExpression.setValue(TagValueExpression.java:95)
           at com.sun.faces.lifecycle.RestoreViewPhase.doPerComponentActions(RestoreViewPhase.java:244)
           at com.sun.faces.lifecycle.RestoreViewPhase.doPerComponentActions(RestoreViewPhase.java:249)
           at com.sun.faces.lifecycle.RestoreViewPhase.doPerComponentActions(RestoreViewPhase.java:249)
           at com.sun.faces.lifecycle.RestoreViewPhase.doPerComponentActions(RestoreViewPhase.java:249)
           at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:193)
           at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
           at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
           at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:44)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
           at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
           at java.lang.Thread.run(Thread.java:595)
          


          Please take notice that in my geoStructureTreeManager I have regular get and set methods:
           private HtmlTree tree1;
           private TreeState treeState;
          
           public HtmlTree getTree1() {
           return tree1;
           }
          
           public void setTree1(HtmlTree tree1) {
           this.tree1 = tree1;
           }
          
           public TreeState getTreeState() {
           return treeState;
           }
          
           public void setTreeState(TreeState treeState) {
           this.treeState = treeState;
           }
          
          


          Has anybody an explanation for this strange behaviour? I really do not know what to think.

          Thanks in advance for your help

          ciao Francesco






          • 2. Re: conversation problem with tree
            milesif

            Hi everybody,

            UPDATE II

            I discovered that if I bind my tree to the bean and set the bean scope to SESSION, I have no problem and when I expand a node (switchType=ajax): everything is fine.
            I made repeated attempts (just to make sure), simply switching ScopeType from SESSION to CONVERSATION and viceversa: this unique change breaks up things when I use the CONVERSATION scope.

            Has anybody any idea? Why if I put my bean in conversation scope I have such problem ?
            I would be really grateful to anybody helping me to understand this behaviour, because I really would prefer to have my bean in CONVERSATION scope.

            Thanks in advance

            Ciao Francesco

            • 3. Re: conversation problem with tree
              milesif

              Hi everybody,

              UPDATE III

              I decided to do some experiments with the sources of the demo from exadel:
              http://livedemo.exadel.com/richfaces-demo/richfaces/tree.jsf;jsessionid=EA3F24DEC4EE3A3FCCED3795917AB017

              I made to changes to those sources:
              1. I set the switchType attribute of the tree to ajax
              2. I set the binding attribute of the tree to a property I added to the bean:

               private UITree tree;
              
               public UITree getTree() {
               return tree;
               }
               public void setTree(UITree tree) {
               this.tree = tree;
               }
              


              What I discovered is that everything is ok when I put the bean in the session scope, while if I put it in the conversation scope I get the usual exception when I expand a node:
              22:22:40,518 WARN [lifecycle] executePhase(RESTORE_VIEW 1,com.sun.faces.context.FacesContextImpl@183bd71) threw exception
              javax.el.PropertyNotFoundException: /tree.xhtml @21,18 binding="#{simpleTreeBean.tree}": Target Unreachable, identifier 'simpleTreeBean' resolved to null
               at com.sun.facelets.el.TagValueExpression.setValue(TagValueExpression.java:95)
               at com.sun.faces.lifecycle.RestoreViewPhase.doPerComponentActions(RestoreViewPhase.java:244)
               at com.sun.faces.lifecycle.RestoreViewPhase.doPerComponentActions(RestoreViewPhase.java:249)
               at com.sun.faces.lifecycle.RestoreViewPhase.doPerComponentActions(RestoreViewPhase.java:249)
               at com.sun.faces.lifecycle.RestoreViewPhase.doPerComponentActions(RestoreViewPhase.java:249)
               at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:193)
               at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
               at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
               at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
               at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              


              I am using jboss4.2.1GA and seam2.0.0GA that I used to generate my project with seam-gen (I really do not remember having made any changes either to the server or to the seam distribution).
              Do you think there is something wrong with my environment ?

              Thanks in advance

              Ciao Francesco


              • 4. Re: conversation problem with tree
                milesif

                Hi everybody

                I found the solution in the seam reference manual

                http://docs.jboss.org/seam/2.0.1.CR1/reference/en/html/conversations.html#d0e5171

                Sorry for bothering you..... I don't know how I skipped or forgot that part.


                Thans a lot

                ciao Francesco

                • 5. Re: conversation problem with tree

                  milesif, this is exactly what I am looking for. I tried following your code but not successful. Can you please post geostructure class to see how it all fits in.

                  Thanks,