11 Replies Latest reply on Aug 19, 2008 12:06 PM by khosro_question

    Please help(@In attribute requires non-null value)

    khosro_question

      Hello Dear members,
      I know this issue has been discussed but i did not understand it and i could not solve my problem,so i post my own issue,with different code,so,please excuse me.


      I read a book that was JBoss Seam: Simplicity and Power Beyond Java EE.I want to  run the Hello World example but i got a error.
      First i write my code then the error:


      ManagerAction.java:


      @Stateless
      @Name("manager")
      public class ManagerAction implements Manager {
      
        @In @Out
        private Person person;
       
        @Out
        private List <Person> fans;
      
        @PersistenceContext
        private EntityManager em;
       
        public String sayHello () {
          em.persist (person);
          person = new Person ();
          fans = em.createQuery("select p from Person p")
                   .getResultList();
          return null;
        }
      
      }
      


      Person.java


      @Entity
      @Name("person")
      public class Person implements Serializable {
      
        private long id;
        private String name;
      
        @Id @GeneratedValue
        public long getId() { return id;}
        public void setId(long id) { this.id = id; }
      
        public String getName() { return name; }
        public void setName(String name) { this.name = name; }
      }
      


      hello.jsp


      <h:inputText value="#{person.name}" size="15"/><br/>
      <h:commandButton type="submit" value="Say Hello"
                       action="#{manager.sayHello}"/>



      The application run but when i click button to save the person in database i get the following error:
      Please help me ,because i can not go on to learn the Seam.


      javax.ejb.EJBTransactionRolledbackException: @In attribute requires non-null value: manager.person
              org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
              org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
              org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
              org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
              org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
              org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
              org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
              org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
              org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
              org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
              org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
              org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
              org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
              org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
              org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
              org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:214)
              org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:184)
              org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:81)
              $Proxy87.sayHello(Unknown Source)
              sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              java.lang.reflect.Method.invoke(Method.java:585)
              org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
              org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
              org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
              org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
              org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
              org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
              org.javassist.tmp.java.lang.Object_$$_javassist_1.sayHello(Object_$$_javassist_1.java)
              sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              java.lang.reflect.Method.invoke(Method.java:585)
              org.apache.el.parser.AstValue.invoke(AstValue.java:131)
              org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
              org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
              javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
              com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
              javax.faces.component.UICommand.broadcast(UICommand.java:383)
              javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:447)
              javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)
              com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
              com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
              com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
              javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
              org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      



      Khosro.















        • 1. Re: Please help(@In attribute requires non-null value)
          mail.micke

          Hi


            @In(create=true) @Out
            private Person person;
          


          Will probably fix that problem, given that you aren't creating a person object somewhere else and want to inject it.


          Or set the required attribute to false if it is ok that it is null.


          - micke

          • 2. Re: Please help(@In attribute requires non-null value)
            mail.micke

            Unrelated, but do you really want to have a stateless session bean that keeps state?

            • 3. Re: Please help(@In attribute requires non-null value)
              khosro_question

              Hello Mikael,
              Thanks for your quick reply.
              I did what you said,i mean ,i put

              @In(create=true)

              ,and ofcourse
              @In(create=true,required=false)

              ,In both of them i did not get the exception anymore,but,when i wirte a name in text filed to save it in DB,the null name column store in database.
              What should i do?
              Best Regards.


              Khosro.

              • 4. Re: Please help(@In attribute requires non-null value)
                khosro_question

                Hello Mikael,
                It is not necessary to use stateful session bean,But i think it is training ,it must work in every situation(either stateless or stateful).
                I am no so comfortable ,if in one of the cases it does not work.
                Thanks.


                Khosro.




                • 5. Re: Please help(@In attribute requires non-null value)
                  khosro_question

                  Hello Mikael,
                  I am really confusing ,because i look at the page 34 of  pdf document(seam-reference.pdf) that is located in doc folder of downloaded Seam ,i saw the following text:



                  When the form is submitted, JSF asks Seam to resolve the variable named user. Since there is no
                  value already bound to that name (in any Seam context), Seam instantiates the user component,
                  and  returns  the  resulting User entity bean  instance  to JSF after storing  it  in  the Seam session
                  context.
                  The form input values are now validated against the Hibernate Validator constraints specified on
                  the User entity. If the constraints are violated, JSF redisplays the page. Otherwise, JSF binds the
                  form input values to properties of the User entity bean.
                  Next, JSF asks Seam to resolve the variable named register. Seam finds the RegisterAction
                  stateless session bean in the stateless context and returns it. JSF invokes the register() action
                  listener method.
                  Seam intercepts the method call and injects the User entity from the Seam session context, before
                  continuing the invocation.



                  so my person object must be created and the textfield value must set to name property of  created person,and when i invoke the action method the person must save in database.
                  But, it seams.it does not happen.Why?


                  Khosro.

                  • 6. Re: Please help(@In attribute requires non-null value)
                    I'm not sure what the example in the book calls for, but I usually make use of the @Factory annotation in this situation.

                    http://docs.jboss.com/seam/2.0.3.CR1/reference/en-US/html_single/

                    Have a look there.

                    Wish I could be more help, the whole injection life cycle thing is still fuzzy for me.
                    • 7. Re: Please help(@In attribute requires non-null value)
                      khosro_question

                      Hello Matt,
                      Thanks.
                      I think ,it  does not in my case.Because when i annotated the person object with
                      '@In',it must be created and because i use El expression ,the name property of user(the already created user) must be set and it must persist in database,but it does not.
                      As far as i understand,'@Factory' use to initialize a context variable,but in my case ,the name property must be initialize automatically when i use EL expression,but it does not.
                      I use seam component to glue the session bean and JSF page ,so i must not use to initialize the name property of user with directing access to JSF page.
                      If  i am wrong please tell me,i am not sure i am right.


                      Khosro.


                      • 8. Re: Please help(@In attribute requires non-null value)
                        khosro_question

                        Hello Dear members,


                        At last, i solved my problem whit replacing  the code in ManagerAction.java class,
                        i replaced


                        
                        
                        @In@Out
                          private Person person;
                        
                           @Out
                          private List <Person> fans



                        with


                         
                         private Person person;
                        private List<Person> fans; 
                        
                        @In
                        public void setPerson (Person person) {
                        this.person = person;
                        }
                        @Out
                        public Person getPerson () {
                        return person;
                        }
                        @Out
                        public List <Person> getFans () {
                        return fans;
                        }


                        and it works.


                        But i have a another problem.I search the forum for this problem ,and found a one


                        http://seamframework.org/Community/PropertyFooNotFoundOnTypeOrgjavassisttmpjavalangObjectjavassist1



                        but it was about using facelets that i do not use it in my project so it was not useful for me.


                        My problem is:
                        I do not want to use Bijection,because i have read some where that overusing Bijection causes bad performance issue.
                        so i changed my code as following:


                        ManagerAction.java:



                        @Stateless
                        @Name("manager")
                        public class ManagerAction implements Manager {
                        
                        
                         private Person person;
                        private List<Person> fans;
                        
                            public void setPerson(Person person) {
                                this.person = person;
                            }
                        
                            public Person getPerson() {
                                return person;
                            }
                        
                            public List<Person> getFans() {
                                return fans;
                            }
                        
                        
                          @PersistenceContext
                          private EntityManager em;
                         
                          public String sayHello () {
                            em.persist (person);
                         // person=new Person();
                            fans = em.createQuery("select p from Person p")
                                     .getResultList();
                            return null;
                          }
                        
                        }
                        



                        hello.jsp:


                        <h:inputText value="#{manager.person.name}" size="15"/><br/>
                        <h:commandButton type="submit" value="Say Hello"
                                         action="#{manager.sayHello}"/>
                        </h:form>
                        
                        <f:subview id="fans"
                                   rendered="#{!empty(manager.fans)}">
                        <f:verbatim>
                        <p>The following fans have said "hello" to JBoss Seam:</p>
                        </f:verbatim>
                        
                        <h:dataTable value="#{manager.fans}" var="fan">
                          <h:column>
                            <h:outputText value="#{fan.name}"/>
                          </h:column>
                        </h:dataTable>
                        </f:subview>



                        But when i run this i get the following error:


                        org.apache.jasper.el.JspPropertyNotFoundException: /hello.jsp(18,0) #{manager.person.name} Property person not found on type org.javassist.tmp.java.lang.Object_$$_javassist_1
                             org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:104)
                             javax.faces.component.UIOutput.getValue(UIOutput.java:173)
                             com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:189)
                             com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:320)
                             com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:200)
                             javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:833)
                             javax.faces.component.UIComponent.encodeAll(UIComponent.java:896)
                             javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
                             javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:809)
                             javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
                             javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
                             com.sun.faces.application.ViewHandlerImpl.doRenderView(ViewHandlerImpl.java:244)
                             com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:175)
                             org.jboss.seam.jsf.SeamViewHandler.renderView(SeamViewHandler.java:87)
                             com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
                             com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
                             com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
                             javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
                             org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)




                        What must i do ?


                        Appreciate form any help.


                        Khosro.





                        • 9. Re: Please help(@In attribute requires non-null value)
                          diegocoronel

                          can you show your interface Manager ? does it have




                          public Person getPerson();


                          ?

                          • 10. Re: Please help(@In attribute requires non-null value)
                            khosro_question

                            Hello Diego,
                            I added getPerson() to interface,and the program start properly,but when i want to persist a person i got the following error:
                            I am really got confusing that this very simple project does not run.



                            org.apache.jasper.el.JspPropertyNotFoundException: /hello.jsp(18,0) '#{manager.person1.name}' Target Unreachable, 'person' returned null
                                 org.apache.jasper.el.JspValueExpression.getType(JspValueExpression.java:61)
                                 com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:81)
                                 javax.faces.component.UIInput.getConvertedValue(UIInput.java:934)
                                 javax.faces.component.UIInput.validate(UIInput.java:860)
                                 javax.faces.component.UIInput.executeValidate(UIInput.java:1065)
                                 javax.faces.component.UIInput.processValidators(UIInput.java:666)
                                 javax.faces.component.UIForm.processValidators(UIForm.java:229)
                                 javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1030)
                                 javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:662)
                                 com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:100)
                                 com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
                                 com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
                                 javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
                                 org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                            


                            Really ,i do not what i must do.
                            Please,please,please help me.
                            Khosro.

                            • 11. Re: Please help(@In attribute requires non-null value)
                              khosro_question

                              Hello Diego, Allen and others,


                              At last, after seeing Seam in Action source code,i understand i must put the following code:


                              private Person person=new Person();


                              instead of


                                private Person person


                              in ManagerAction.java.(I understand it from Allen's source code)


                              And also put the following code in the interface:(I understand it from Diego's hint)


                              public Person getPerson();



                              Thanks to Diego that gives me some clue and also Dan Allen for his source code.


                              Thanks.


                              Khosro.