1 2 Previous Next 15 Replies Latest reply on Aug 10, 2006 9:17 AM by ypasmk

    Injection problem

    ypasmk

      I can inject with seam as it seems


      My user class

      
      @Entity
      @Table(name="USERS")
      @Name("user")
      @Scope(SESSION)
      public class User implements Serializable
      {
       private String username;
       private String password;
       private String name;
      
       public User(String name, String password, String username)
       {
       this.name = name;
       this.password = password;
       this.username = username;
       }
      
       public User() {}
      
       @NotNull
       @Length(max=100)
       public String getName()
       {
       return name;
       }
       public void setName(String name)
       {
       this.name = name;
       }
      
       @NotNull
       @Length(min=5, max=15)
       public String getPassword()
       {
       return password;
       }
       public void setPassword(String password)
       {
       this.password = password;
       }
      
       @Id
       @Length(min=5, max=15)
       @Pattern(regex="^\\w*$", message="not a valid username")
       public String getUsername()
       {
       return username;
       }
       public void setUsername(String username)
       {
       this.username = username;
       }
      
       public String toString()
       {
       return "User(" + username + ")";
       }
      }
      
      



      My registerAction class
      @Stateful
      
      @Scope(EVENT)
      
      @Name("register")
      
      public class RegisterAction implements Register
      
      {
      
      
      
       @In(create = true)
      
       private User user;
      
      
      
       @PersistenceContext
      
       private EntityManager em;
      
      
      
       @In(create=true)
      
       private transient FacesMessages facesMessages;
      
      
      
       private String verify;
      
      
      
       public String register()
      
       {
      
      
      
      
      
      
      
       if ( user.getPassword().equals("hi") )
      
       {
      
       List existing = em.createQuery("select username from User where username=:username")
      
       .setParameter("username", user.getUsername())
      
       .getResultList();
      
       if (existing.size()==0)
      
       {
      
       em.persist(user);
      
       facesMessages.add("Successfully registered as #{user.username}");
      
       return "/registered.xhtml";
      
       }
      
       else
      
       {
      
       facesMessages.add("Username #{user.username} already exists");
      
       return null;
      
       }
      
       }
      
       else
      
       {
      
       facesMessages.add("verify", "Re-enter your password");
      
       verify=null;
      
       return null;
      
       }
      
       }
      
      
      
       public String getVerify()
      
       {
      
       return verify;
      
       }
      
      
      
       public void setVerify(String verify)
      
       {
      
       this.verify = verify;
      
       }
      
      
      
       @Destroy @Remove
      
       public void destroy() {}
      
      }
      
      


      and my xhtml page

       <h:form id="testForm">
      <s:validateAll>
      <h:inputText value="#{user.username}" />
      <h:inputText value="#{user.password}" />
      <h:inputText value="#{user.name}" />
      <h:commandButton value="Submit" action="#{register.register}" />
      </s:validateAll>
      <h:messages />
      </h:form>
      
      



      my problem is that I get this exception

      javax.faces.FacesException: Error calling action method of component with id testForm:_id11
       at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)
       at javax.faces.component.UICommand.broadcast(UICommand.java:106)
       at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:94)
       at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:168)
       at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:343)
       at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.seam.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter.java:30)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       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.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
       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:869)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
       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: /register.xhtml @84,72 action="#{register.register}": javax.ejb.EJBException: java.lang.NullPointerException
       at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:73)
       at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
       ... 27 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:197)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:81)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:188)
       at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:98)
       at $Proxy306.register(Unknown Source)
       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 com.sun.el.parser.AstValue.invoke(AstValue.java:151)
       at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)
       at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
       at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java:69)
       ... 28 more
      Caused by: java.lang.NullPointerException
       at uai.blogic.RegisterAction.register(RegisterAction.java:44)
       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.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
       at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
       ... 51 more
      


        • 1. Re: Injection problem
          pmuir

          You have an NPE at line 44 of RegisterAction. What is on line 44?

          • 2. Re: Injection problem
            ypasmk

            I'm calling this method online 44 user.getPassword(). is like nothing comes from the context in my ejb so the user is null but why?

            • 3. Re: Injection problem
              bfo81

              Are you sure your user is null? Maybe getPassword() is null.

              Try to output user and user.getPassword() to you log (System.out.println("user: " + user); System.out.println("password: " + user.getPassword()); should be sufficient).

              btw: I guess that EVENT scope might be too short.

              • 4. Re: Injection problem
                ypasmk

                I debug at the user is null. FacesMessages also null. Only the entityManager is not null

                • 5. Re: Injection problem
                  ypasmk

                  Also I set the scope to SESSION but still the user and FacesMessages are null.

                  • 6. Re: Injection problem
                    ypasmk

                    And the funny thing is that this code is copy paste from the seam booking examples that works just fine

                    • 7. Re: Injection problem
                      pmuir

                      Is the component being initialised by Seam when the application starts (look at the log)?

                      • 8. Re: Injection problem
                        pmuir

                        Actually, forget that. Do you have the interceptors set up properly in ejb-jar.xml?

                        • 9. Re: Injection problem
                          ypasmk

                          this is my ejb-jar.xml

                          <ejb-jar>
                           <assembly-descriptor>
                           <interceptor-binding>
                           <ejb-name>*</ejb-name>
                           <interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
                           </interceptor-binding>
                           </assembly-descriptor>
                          </ejb-jar>
                          


                          problem solved by placing
                          @Interceptors(SeamInterceptor.class)
                          


                          in my RegisterAction ejb

                          but why do I need this?

                          • 10. Re: Injection problem
                            raja05

                            Does your Register Interface define the register() method ?

                            • 11. Re: Injection problem
                              pmuir

                              Do you have session beans in the archive that injection is fine on? If yes, then I'm unsure of the problem, otherwise for some reason the ejb-jar.xml setting is not being applied.

                              • 12. Re: Injection problem
                                ypasmk

                                well I'm not sure if what I'm going to say is stupid but User entity is in the entities package and register in the blogic package. So they are in different packages..Does that matter?

                                • 13. Re: Injection problem
                                  pmuir

                                  Package - certainly not :) As long as the archive which has the session bean in has the ejb-jar.xml file in its META-INF then it should work with an explicit @Interceptors

                                  • 14. Re: Injection problem
                                    ypasmk

                                    You are refering to the packaging configuration? If yes all my classes are in the jar archive but I don't have the ejb-jar.xml there. I'll try that. Now I have another issue. I want to use utf-16 by default so I wrote a class filter and I put those lines in my web.xml

                                     <filter>
                                     <filter-name>Charset Filter</filter-name>
                                     <filter-class>uai.utilities.CharsetFilter</filter-class>
                                     <init-param>
                                     <param-name>requestEncoding</param-name>
                                     <param-value>UTF-16</param-value>
                                     </init-param>
                                     </filter>
                                    
                                    
                                     <filter-mapping>
                                     <filter-name>Charset Filter</filter-name>
                                     <url-pattern>/*</url-pattern>
                                     </filter-mapping>
                                    


                                    my filter class

                                    public class CharsetFilter implements Filter
                                    {
                                     private String encoding;
                                    
                                     public void init(FilterConfig config) throws ServletException
                                     {
                                     encoding = config.getInitParameter("requestEncoding");
                                    
                                     if( encoding==null ) encoding="UTF-16";
                                     }
                                    
                                     public void doFilter(ServletRequest request, ServletResponse response, FilterChain next)
                                     throws IOException, ServletException
                                     {
                                     request.setCharacterEncoding(encoding);
                                     next.doFilter(request, response);
                                     }
                                    
                                     public void destroy(){}
                                    }
                                    


                                    then when I deploy my app and hit the register button is like method is never called and no messages with h:messages. If I replace the UTF-16 with UTF-8 everything works fine. That means that UTF-16 is not supported? And also when I check the character encoding in my page it is UTF-16

                                    1 2 Previous Next