6 Replies Latest reply on Oct 5, 2009 12:52 PM by Peter Neuburger

    DataModel and Factory Method

    Peter Neuburger Newbie

      Hello,


      I am using a @DataModel in my richfaces:datatable with a preloading action method call.
      So when I access the page I want to load all the Datas.


      so in my pages.xml there is a navigation rule.






      page view-id="/mypage.xml"
       action execute="#{myBean.preloadData}" 
      


      so in my xhtml page


      richfaces:dataTable value="#{myBean.dataModel}"
      



      in myBean


      /** Datentabelle */
      @DataModel(scope = ScopeType.PAGE)
      private List<Glas> glasDataModel ;
      
      /** Query Class */
      @In(create = true ) 
      private GlasQuery glasQuery ; 
      
      /** Factory method, I thought to avoid a NullPointer 
      * from this hint.
      *
      * http://docs.jboss.com/seam/1.2.0.PATCH1/reference/en/html/concepts.html#d0e3190
      */
      @Factory("glasDataModel")
      public void preLoading() {
       glasDataModel = glasQuery.getResultList();
      }
      



      but I always get a NullPointer Exception.


      so what can I do ??




        • 1. Re: DataModel and Factory Method
          Nagendra krishnawat Newbie

          As far as I know, If you are using annotation @DataModel then you don't need to use @Factory. Because @Datamodel itself is outjecting the variable in seam context.


          Secondly your @Factory method has return type void, this seems to be wrong as it should return some value to go in seam context.

          • 2. Re: DataModel and Factory Method
            Peter Neuburger Newbie

            Hello,


            did you read the Documentation.


            http://docs.jboss.com/seam/1.2.0.PATCH1/reference/en/html/concepts.html#d0e3190
            


            then you will see why Iam using the @Factory method with return type void.


            Regards

            • 3. Re: DataModel and Factory Method
              blabno Master

              Full stacktrace please.

              • 4. Re: DataModel and Factory Method
                Peter Neuburger Newbie

                now i get another error ???



                java.lang.IllegalArgumentException: Cannot convert org.jboss.seam.jsf.ListDataModel@e54d8 of type class org.jboss.seam.jsf.ListDataModel to class java.lang.Boolean
                     at org.jboss.el.lang.ELSupport.coerceToBoolean(ELSupport.java:177)
                     at org.jboss.el.parser.AstAnd.getValue(AstAnd.java:27)
                     at org.jboss.el.parser.AstDeferredExpression.getValue(AstDeferredExpression.java:26)
                     at org.jboss.el.parser.AstCompositeExpression.getValue(AstCompositeExpression.java:31)
                     at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
                     at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
                     at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:390)
                     at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
                     at javax.faces.render.Renderer.encodeChildren(Renderer.java:148)
                     at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
                     at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
                     at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
                     at org.richfaces.renderkit.TabRendererBase.encodeChildren(TabRendererBase.java:113)
                     at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
                     at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
                     at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
                     at org.richfaces.renderkit.html.TabPanelRenderer.doEncodeChildren(TabPanelRenderer.java:286)
                     at org.richfaces.renderkit.html.TabPanelRenderer.doEncodeChildren(TabPanelRenderer.java:281)
                     at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:121)
                     at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
                     at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
                     at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
                     at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:220)
                     at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:215)
                     at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:121)
                     at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
                     at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
                     at javax.faces.component.UIComponent.encodeAll(UIComponent.java:942)
                     at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
                     at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
                     at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:196)
                     at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:109)
                     at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
                     at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
                     at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
                     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:90)
                     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.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.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
                     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.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
                     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(Unknown Source)

                • 5. Re: DataModel and Factory Method
                  blabno Master

                  One thing is here :


                  richfaces:dataTable value="#{myBean.dataModel}"



                  If you annotate a property with @DataModel then it will become context variable, so you do not need to reference the bean. #{glasDataModel} would be enough.


                  Other thing is that you do not have dataModel property on your bean. You have glasDataModel and it is not even a property (no getter), it's just an attribute.


                  As to cannot convert exception, it seems in your facelet in some render attribute you call wrong expression. I'm guessing you do this


                  <sometag ... rendered="#{glasDataModel}"/>



                  instead of


                  <sometag ... rendered="#{glasDataModel.rowCount > 0}"/>


                  • 6. Re: DataModel and Factory Method
                    Peter Neuburger Newbie

                    Hi Bernard,


                    you´re right, i had an error in

                    #{myBean.dataModel}

                    , so I fixed it. And yes I had an Error in the rendered Attribute. Fixed it also. Everything works fine now.


                    thanks


                    peter