3 Replies Latest reply on Feb 24, 2009 5:43 PM by fridgebuzz

    Factory "component" resolves to null only in non-debug mode

    fridgebuzz

      Hi,


      I'm testing my application with debug (hot deploy) turned off in order to track down a bug which may be related to it: see discussion at Observer Methods Being Called Multiple Times.


      Unfortunately, I'm seeing an error I don't see with debug turned on, namely a Factory component is resolving to null on form submission. Here are some details to explain.


      The Factory in question looks like this:



      @Name("currentUserHome")
      @Scope(value=ScopeType.CONVERSATION)
      @AutoCreate
      public class CurrentUserHome extends UserHome {
         
        @Factory(value="currentUser", 
                 scope=ScopeType.STATELESS, 
                 autoCreate=true)
        public User getCurrentUser() {           
            return getInstance();       
        }
      



      You may question why the scope is STATELESS and all I can say is that a colleague working on the Ajax side of the application had lifecycle issues that couldn't be resolved without making this Factory STATELESS. In any event, as far as I understand it, it means that every time currentUser is accessed, the Factory will be called to retrieve its value. Because this class extends the framework class EntityHome, this Factory can never return null.


      So... I have a registration form with a number of fields which reference currentUser. Just one as an example:



      <s:decorate id="usernameField" template="layout/edit.xhtml">
           <ui:define name="label">Screen Name</ui:define>
           <h:inputText id="username" value="#{currentUser.userName}" size="20" required="true"/>
      </s:decorate>
      



      The page renders without complaint, I can fill in all the fields, and when I hit the action button, I get the following exception



      WARN  [lifecycle] /register.xhtml @42,92 value="#{currentUser.primaryEmail}": Target Unreachable, identifier 'currentUser' resolved to null
      javax.el.PropertyNotFoundException: /register.xhtml @42,92 value="#{currentUser.primaryEmail}": Target Unreachable, identifier 'currentUser' resolved to null
           at com.sun.facelets.el.TagValueExpression.getType(TagValueExpression.java:62)
           at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:92)
           at javax.faces.component.UIInput.getConvertedValue(UIInput.java:942)
           at javax.faces.component.UIInput.validate(UIInput.java:868)
           at javax.faces.component.UIInput.executeValidate(UIInput.java:1072)
           at javax.faces.component.UIInput.processValidators(UIInput.java:672)
           at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
           at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
           at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
           at javax.faces.component.UIForm.processValidators(UIForm.java:235)
           at org.ajax4jsf.component.AjaxViewRoot$3.invokeContextCallback(AjaxViewRoot.java:439)
           at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:238)
           at org.ajax4jsf.component.AjaxViewRoot.processValidators(AjaxViewRoot.java:455)
           at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
           at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
           at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
           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.web.IdentityFilter.doFilter(IdentityFilter.java:40)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:86)
           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:45)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
           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:182)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
           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:262)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
           at java.lang.Thread.run(Thread.java:637)



      ...and many more besides, but the common theme is that currentUser resolves to null. Setting a breakpoint in the Factory shows that it is never called.


      To compare: when debug is on, the Factory is called and everything works as you'd expect.


      So... I'm quite stumped. I did not expect turning debug off to change the way the application functions. I must have done something grievously wrong. Any suggestions greatly appreciated as always.


      Cheers,


      Vanessa

        • 1. Re: Factory "component" resolves to null only in non-debug mode
          mwohlf
          just a long shot:
          make sure your #{currentUser} component is not in the dev/ Folder when your App is deployed since this is the hotdeploy folder and only checked when debug/hotdeploy is on.
          • 2. Re: Factory "component" resolves to null only in non-debug mode
            fridgebuzz

            I think you may be onto something there, Michael. I'm using Eclipse (Jboss Dev Studio), which isn't my favourite, but... that's another story. Anyhow, it seems to insist on putting all the .class files in WEB-INF/dev and all that's in WEB-INF/classes is source files (WTF?) So that could explain why it can't find any code (and this is just the first place I run into it in my test case.)


            Now I have to figure out how to get Eclipse to deploy the project properly for non-debug mode.


            Thanks for the suggestion, I think this really might be it.


            Cheers,


            Vanessa

            • 3. Re: Factory "component" resolves to null only in non-debug mode
              fridgebuzz

              Ok, Michael, that was it! Getting the app deployed and started with all the class files where they belonged had to be done by hand (JBDS insists on putting the action classes in /dev no matter what), but it solved that problem. Now onto my original one ;-)


              Thanks again,


              Vanessa