3 Replies Latest reply on Feb 8, 2006 2:44 AM by newlukai

    Injecting doesn't work

      Hi folks,

      I've searched the forum, but I didn't find a topic solving my problem.

      I modified the booking example to test the capabilities of Seam. I have to say, Seam is very nice.
      As I said, I modified the booking example. I left the LoginAction as it was. After logging in, the user sees a personalized welcome message. The Name is retrieved from a database. It works fine. The User enters his token and is welcomed with his name.
      A panelNavigation2 (nested in a f:view) displays some sort of navigation in the sidebar. As you see, I use myFaces. One of the navigation Items calls a method in a stateless bean, where I want the user component to be injected. But this doesn't work. Debugging this code reveals that as soon as the called method is invoked, user equals null. I don't know, what's wrong with my code. It's similar to the booking example (i.e. ChangePasswordAction).

      User.java:

      package myprog.entities;
      
      import java.io.Serializable;
      
      import javax.persistence.Column;
      import javax.persistence.Entity;
      import javax.persistence.Id;
      import javax.persistence.Table;
      
      import org.hibernate.validator.Length;
      import org.hibernate.validator.NotNull;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import static org.jboss.seam.ScopeType.SESSION;
      
      @Entity
      @Table(name="USERS")
      @Name("user")
      @Scope(SESSION)
      public class User implements Serializable {
       private String m_ID;
       private String m_Name;
       private String m_Phone;
       private String m_Email;
       private int m_isDeveloper;
       private int m_isTester;
       private Integer m_isAdmin;
       private String m_Password;
       private String m_TOTRoot;
       private String m_PWToken;
       private Integer m_isQPV;
      
       public User(String p_id, String p_name, String p_password, String p_email, String p_phone) {
       super();
       m_ID = p_id;
       m_Name = p_name;
       m_Password = p_password;
       m_Email = p_email;
       m_Phone = p_phone;
       }
      
       public User() {
       }
      
       @Column(name="USR_ID")
       @Id
       @NotNull
       @Length(min=2, max=10)
       public String getID() {
       return m_ID;
       }
      
       //Here follow all the needed getters and setters
      }


      The LoginAction:
      package myprog.sessions;
      
      import java.util.List;
      
      import javax.ejb.Interceptor;
      import javax.ejb.Stateful;
      import javax.ejb.Stateless;
      import javax.faces.application.FacesMessage;
      import javax.faces.context.FacesContext;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.contexts.Context;
      import org.jboss.seam.ejb.SeamInterceptor;
      
      import myprog.entities.User;
      
      @Stateless
      @Name("login")
      @Interceptor(SeamInterceptor.class)
      public class LoginAction implements ILogin {
       @In @Out
       private User user;
      
       @PersistenceContext(unitName="myProgDatabase")
       private EntityManager em;
      
       @In
       private Context sessionContext;
      
       @In
       private FacesContext facesContext;
      
       public String login() {
       List<User> results = em.createQuery(
       "from User where ID=:username")
       .setParameter("username", user.getID()).getResultList();
      
       if (results.size() == 0) {
       facesContext.addMessage(null, new FacesMessage("Invalid login"));
       return "login";
       } else {
       user = results.get(0);
       sessionContext.set("loggedIn", true);
       return "main";
       }
      
       }
      }


      Here is the component with the called method:
      package myprog.sessions;
      
      import java.util.List;
      
      import javax.ejb.Interceptor;
      import javax.ejb.Stateful;
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      import org.hibernate.validator.Valid;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.contexts.Context;
      import org.jboss.seam.ejb.SeamInterceptor;
      
      import myprog.entities.Testaction;
      import myprog.entities.User;
      
      @Stateless
      @LoggedIn
      @Name("showListForDevelopers")
      @Interceptor(SeamInterceptor.class)
      public class ShowListForDevelopers implements IShowListForDevelopers {
       @PersistenceContext(unitName = "myProgDatabase")
       private EntityManager em;
      
       @In @Valid
       private User user;
      
       public Testaction[] getTestactions() {
       List<Testaction> result = em.createQuery(
       "from Testaction where DevUsrID=:dev order by ID asc"
       ).setParameter("dev", user.getID()).getResultList();
       return result.toArray(new Testaction[result.size()]);
       }
      }


      As I said, in getTestactions() the user isn't injected. Has anybody any idea?
      Might be it's important to know, that the method is called from a panelNavigation2 item. But I think, this shouldn't make any difference.

      Thank you
      Newlukai

        • 1. Re: Injecting doesn't work

          Here is the stacktrace:

          javax.faces.el.EvaluationException: /showListForDeveloper.xhtml @12,78 value="#{showListForDevelopers.testactions}": $Proxy104
           at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:60)
           at javax.faces.component.UIData.getValue(UIData.java:779)
           at org.apache.myfaces.component.html.ext.HtmlDataTableHack.createDataModel(HtmlDataTableHack.java:350)
           at org.apache.myfaces.component.html.ext.HtmlDataTableHack.getDataModel(HtmlDataTableHack.java:333)
           at org.apache.myfaces.component.html.ext.HtmlDataTable.getDataModel(HtmlDataTable.java:428)
           at org.apache.myfaces.component.html.ext.HtmlDataTableHack.getRowCount(HtmlDataTableHack.java:75)
           at org.apache.myfaces.renderkit.html.HtmlTableRendererBase.encodeInnerHtml(HtmlTableRendererBase.java:124)
           at org.apache.myfaces.renderkit.html.HtmlTableRendererBase.encodeChildren(HtmlTableRendererBase.java:94)
           at org.apache.myfaces.renderkit.html.ext.HtmlTableRenderer.encodeChildren(HtmlTableRenderer.java:57)
           at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:319)
           at com.sun.facelets.FaceletViewHandler.encodeRecursive(FaceletViewHandler.java:539)
           at com.sun.facelets.FaceletViewHandler.encodeRecursive(FaceletViewHandler.java:544)
           at com.sun.facelets.FaceletViewHandler.encodeRecursive(FaceletViewHandler.java:544)
           at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:450)
           at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:352)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:107)
           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:81)
           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:39)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
           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:856)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
           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(Thread.java:595)
          Caused by: javax.faces.el.EvaluationException: Bean: $Proxy104, property: testactions
           at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:404)
           at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:71)
           at com.sun.facelets.el.LegacyELContext$LegacyELResolver.getValue(LegacyELContext.java:141)
           at com.sun.el.parser.AstValue.getValue(AstValue.java:96)
           at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:183)
           at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
           at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:56)
           ... 34 more
          Caused by: java.lang.reflect.InvocationTargetException
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:585)
           at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:400)
           ... 40 more
          Caused by: javax.ejb.EJBException: null; CausedByException is:
           null
           at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:46)
           at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:70)
           at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:134)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
           at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:61)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
           at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:39)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
           at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:63)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
           at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:32)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
           at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:91)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
           at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:148)
           at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:60)
           at $Proxy104.getTestactions(Unknown Source)
           ... 45 more


          • 2. Re: Injecting doesn't work
            gavin.king

            Try @Intercept(ALWAYS), or upgrade to CVS version of Seam, where that is the new default.

            • 3. Re: Injecting doesn't work

              Thanks Gavin. This solved my problem.
              I added the annotation @Intercept(ALWAYS) to my stateless session bean.

              Regards
              Newlukai