3 Replies Latest reply on Feb 5, 2007 5:50 PM by Gavin King

    exception when using ScopeType.CONVERSATION and h:panelGrid

    Charles Crouch Expert

      I've got the following dummy app based on the numberGuess example (Seam 1.1GA, JSF 1.2RI, Facelets):

      .xhtml

      ...
      <h:panelGrid binding="#{numberGuess.dynamicPanelGrid}" />
      
      Your guess:
      <h:inputText value="#{numberGuess.currentGuess}" id="guess" required="true"/>
      
      <h:commandButton value="Guess" action="#{numberGuess.testAction}"/>
      ...


      .java

      @Name("numberGuess")
      public class NumberGuess {
      ...
       private Integer currentGuess;
       private HtmlPanelGrid grid;
      
       @Create
       public void begin()
       {
       log.info("Entering begin()");
       }
      
       public void setCurrentGuess(Integer guess)
       {
       this.currentGuess = guess;
       }
      
       public Integer getCurrentGuess()
       {
       return currentGuess;
       }
      
       public String testAction() {
       currentGuess = currentGuess + 1;
       return null;
       }
      
      
      
       public HtmlPanelGrid getDynamicPanelGrid() {
       if (grid == null) {
       Application app = FacesContext.getCurrentInstance().getApplication();
       grid = (HtmlPanelGrid) app.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
      
       HtmlOutputText text = (HtmlOutputText) app.createComponent(HtmlOutputText.COMPONENT_TYPE);
       text.setValue("Hello World");
       grid.getChildren().add(text);
       }
      
       return grid;
       }
      
       public void setDynamicPanelGrid(HtmlPanelGrid aGrid){
       grid = aGrid;
       }
       ...
      



      So far so good, everything works great when I render the page the first time: I get the Hello World message and an empty textbox. Entering a number in the box and hitting Guess refreshes the page with Hello World and number+1 displayed, exactly as expected.

      Now I want to make the scope of this numberGuess bean to be Conversational so I don't get a new instance each time. So I add @Scope
      @Name("numberGuess")
      @Scope(ScopeType.CONVERSATION)
      public class NumberGuess {
      


      and

      @Begin

      @Create
       @Begin
       public void begin()
       {
      


      Now when I render the page the first time again, everything is great as before. Enter a number and hit Guess, before it gets to any of my breakpoints on the java side, it goes bang...

      HTTP Status 500 -
      
      --------------------------------------------------------------------------------
      
      type Exception report
      
      message
      
      description The server encountered an internal error () that prevented it from fulfilling this request.
      
      exception
      
      javax.servlet.ServletException: /numberGuess.xhtml @18,66 binding="#{numberGuess.dynamicPanelGrid}": Target Unreachable, identifier 'numberGuess' resolved to null
       org.jboss.seam.servlet.SeamExceptionFilter.doFilter(SeamExceptionFilter.java:61)
       org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      
      
      root cause
      
      javax.servlet.ServletException: /numberGuess.xhtml @18,66 binding="#{numberGuess.dynamicPanelGrid}": Target Unreachable, identifier 'numberGuess' resolved to null
       javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
       org.jboss.seam.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter.java:32)
       org.jboss.seam.servlet.SeamExceptionFilter.doFilter(SeamExceptionFilter.java:46)
       org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      
      
      root cause
      
      javax.el.PropertyNotFoundException: /numberGuess.xhtml @18,66 binding="#{numberGuess.dynamicPanelGrid}": Target Unreachable, identifier 'numberGuess' resolved to null
       com.sun.facelets.el.TagValueExpression.setValue(TagValueExpression.java:95)
       com.sun.faces.lifecycle.RestoreViewPhase.doPerComponentActions(RestoreViewPhase.java:258)
       com.sun.faces.lifecycle.RestoreViewPhase.doPerComponentActions(RestoreViewPhase.java:263)
       com.sun.faces.lifecycle.RestoreViewPhase.doPerComponentActions(RestoreViewPhase.java:263)
       com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:225)
       com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:244)
       com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:113)
       javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
       org.jboss.seam.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter.java:32)
       org.jboss.seam.servlet.SeamExceptionFilter.doFilter(SeamExceptionFilter.java:46)
       org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      
      



      Take out the...

      <h:panelGrid binding="#{numberGuess.dynamicPanelGrid}" />


      from the .xhtml and everything works great. The numbers update as before and begin() only gets called once, as expected.

      So.... what am I doing which causes a panelGrid bound to a bean property to blow up when using ScopeType.CONVERSATION ?

      Thanks