8 Replies Latest reply on Mar 26, 2006 6:19 PM by gavin.king

    injection of @DataModelSelection fails with value() attribut

    frege

      I've encountered a problem in my application that I was eventually able to reproduce with a simple change to the messages example. If you add a value attribute to the @DataModelSelection annotation, e.g.

      @DataModelSelection("message")

      Seam will fail to inject the selected object (message) when select() is called, causing a null pointer exception at the first reference. The potential ambiguity with the 'message' context variable introduced by Message.java is not the cause. You will get the same behaviour if you rename MessageListBean.java's 'message ' attribute to 'message2' and use @DataModelSelection("message2") instead.

      You may wonder why I am using the undocumented value() attribute on @DataModelSelection. This all started because I was attempting to use two @DataModels in my statefull session component (two different @DataModel attribute names, two different @DataModelSelection attribute names, no use of the value attribute). The component fails to deploy with the following error:
      10:24:28,341 ERROR [[/seam-messages]] Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
      java.lang.IllegalStateException: Missing value() for @DataModelSelection with multiple @DataModels

      The documentation doesn't list a value() attribute for the @DataModelSelection annotation. Adding the value attribute to the two @DataModelSelection annotations (same name as the attribute) fixes the deployment problem, but causes the injection failure/null pointer problem.

      Is this a bug? Is there a way to employ two @DataModels without using the value() attribute on @DataModelSelection?

      Thanks

        • 1. Re: injection of @DataModelSelection fails with value() attr
          gavin.king

          Can you show me the stack trace of the NPE?

          • 2. Re: injection of @DataModelSelection fails with value() attr
            frege

            13:16:10,705 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
            javax.faces.FacesException: Error calling action method of component with id _id0:_id2_0:_id8
            at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)
            at javax.faces.component.UICommand.broadcast(UICommand.java:106)
            at javax.faces.component.UIData.broadcast(UIData.java:338)
            at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
            at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:164)
            at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:316)
            at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
            at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
            at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
            at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:54)
            at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:174)
            at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
            at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
            at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
            at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
            at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
            at java.lang.Thread.run(Unknown Source)
            Caused by: javax.faces.el.EvaluationException: Exception while invoking expression #{messageList.select}
            at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:153)
            at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
            ... 26 more
            Caused by: javax.ejb.EJBException: java.lang.NullPointerException
            at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
            at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
            at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:192)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:81)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:190)
            at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:98)
            at $Proxy69.select(Unknown Source)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
            ... 27 more
            Caused by: java.lang.NullPointerException
            at org.jboss.seam.example.messages.MessageListBean.select(MessageListBean.java:51)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:109)
            at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:168)
            at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
            at org.jboss.seam.interceptors.ValidationInterceptor.validateTargetComponent(ValidationInterceptor.java:65)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
            at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
            at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
            at org.jboss.seam.interceptors.OutcomeInterceptor.interceptOutcome(OutcomeInterceptor.java:21)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
            at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
            at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
            at org.jboss.seam.interceptors.RollbackInterceptor.rollbackIfNecessary(RollbackInterceptor.java:30)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
            at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
            at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
            at org.jboss.seam.interceptors.BijectionInterceptor.bijectTargetComponent(BijectionInterceptor.java:32)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
            at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
            at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
            at org.jboss.seam.interceptors.ConversationInterceptor.endOrBeginLongRunningConversation(ConversationInterceptor.java:58)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
            at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
            at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
            at org.jboss.seam.interceptors.BusinessProcessInterceptor.manageBusinessProcessContext(BusinessProcessInterceptor.java:58)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
            at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
            at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
            at org.jboss.seam.interceptors.RemoveInterceptor.removeIfNecessary(RemoveInterceptor.java:38)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
            at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:87)
            at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:60)
            at org.jboss.seam.ejb.SeamInterceptor.aroundInvoke(SeamInterceptor.java:41)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:120)
            at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:62)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:71)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
            at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
            ... 47 more

            • 3. Re: injection of @DataModelSelection fails with value() attr
              gavin.king

              P.S. I have now refreshed the documentation of the datamodel stuff. Thanks for pointing out it was missing.

              • 4. Re: injection of @DataModelSelection fails with value() attr
                gavin.king

                OK, so no message is being injected into the DataModelSelection. (There is no NPE in Seam, the NPE is in the application.)

                Please show me the code of the MessageList class.

                • 5. Re: injection of @DataModelSelection fails with value() attr
                  frege

                  The only change from the original is line 37 for line 36:

                  //$Id: MessageListBean.java,v 1.2 2006/01/14 20:13:46 gavin Exp $
                  package org.jboss.seam.example.messages;
                  
                  import static org.jboss.seam.ScopeType.SESSION;
                  import static javax.persistence.PersistenceContextType.EXTENDED;
                  
                  import java.io.Serializable;
                  import java.util.List;
                  
                  import javax.ejb.Interceptors;
                  import javax.ejb.Remove;
                  import javax.ejb.Stateful;
                  import javax.persistence.EntityManager;
                  import javax.persistence.PersistenceContext;
                  
                  import org.jboss.seam.annotations.Destroy;
                  import org.jboss.seam.annotations.Factory;
                  import org.jboss.seam.annotations.Name;
                  import org.jboss.seam.annotations.Out;
                  import org.jboss.seam.annotations.Scope;
                  import org.jboss.seam.annotations.datamodel.DataModel;
                  import org.jboss.seam.annotations.datamodel.DataModelSelection;
                  import org.jboss.seam.ejb.SeamInterceptor;
                  
                  @Stateful
                  @Scope(SESSION)
                  @Name("messageList")
                  @Interceptors(SeamInterceptor.class)
                  public class MessageListBean implements Serializable, MessageList
                  {
                  
                   @DataModel
                   private List<Message> messages;
                  
                   @Out(required=false)
                  // @DataModelSelection
                   @DataModelSelection("message")
                   private Message message;
                  
                   @PersistenceContext(type=EXTENDED)
                   private EntityManager em;
                  
                   @Factory("messages")
                   public void findMessages()
                   {
                   messages = em.createQuery("from Message msg order by msg.datetime desc").getResultList();
                   }
                  
                   public String select()
                   {
                   message.setRead(true);
                   return "selected";
                   }
                  
                   public String delete()
                   {
                   messages.remove(message);
                   em.remove(message);
                   message=null;
                   return "deleted";
                   }
                  
                   @Remove @Destroy
                   public void destroy() {}
                  
                  }
                  


                  • 6. Re: injection of @DataModelSelection fails with value() attr
                    gavin.king

                    The value() of the @DataModelSelection must be the name of the DataModel context variable. Which in this case is "messages". If you want to change that, you need to have:

                    * @DataModel("foo")
                    * @DataModelSelection("foo")
                    * @Factory("foo")

                    • 7. Re: injection of @DataModelSelection fails with value() attr
                      frege

                      Ah ha! Since it was (previously) undocumented, I assumed it was named after its own attribute variable, like the doc says for @DataModel. I even tried naming it after the "var" in the JSF dataTable.

                      Thanks for the promt attention.

                      • 8. Re: injection of @DataModelSelection fails with value() attr
                        gavin.king