9 Replies Latest reply on Nov 21, 2007 5:24 AM by Pete Muir

    selectOneMenu - NPE

    Bartosz Jamroz Newbie

      I`m getting NPE when using selectOneMenu, why is that ?

      view

      <h:selectOneMenu value="#{questionCategory}" required="true">
       <s:selectItems value="#{questionCategoryList}" var="category" label="#{category.categoryName}"/>
       <s:convertEntity/>
       </h:selectOneMenu>
      


      components.xml
      <components xmlns="http://jboss.com/products/seam/components"
       xmlns:core="http://jboss.com/products/seam/core"
       xmlns:security="http://jboss.com/products/seam/security"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation=
       "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-1.2.xsd
       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-1.2.xsd
      http://jboss.com/products/seam/components http://jboss.com/products/seam/components-1.2.xsd">
      
       <component name="org.jboss.seam.core.init">
       <property name="debug">true</property>
       <property name="myFacesLifecycleBug">true</property>
       <property name="jndiPattern">Inquisitor/#{ejbName}/local</property>
       </component>
      
       <component class="org.jboss.seam.web.MultipartFilter">
       <property name="createTempFiles">true</property>
       <property name="maxRequestSize">1000000</property>
       </component>
      
       <core:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/EntityManagerFactory"/>
      </components>
      


        • 1. Re: selectOneMenu - NPE
          Bartosz Jamroz Newbie

          Exception

          10:40:36,766 ERROR [STDERR] Nov 19, 2007 10:40:36 AM com.sun.facelets.FaceletViewHandler handleRenderException
          SEVERE: Error Rendering View[/question.xhtml]
          java.lang.NullPointerException
           at org.jboss.seam.ui.converter.EntityConverterStore.getEntityManager(EntityConverterStore.java:81)
           at org.jboss.seam.ui.converter.EntityConverterStore.put(EntityConverterStore.java:60)
           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.seam.util.Reflections.invoke(Reflections.java:21)
           at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
           at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:38)
           at org.jboss.seam.util.Work.workInTransaction(Work.java:40)
           at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:32)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:106)
           at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:155)
           at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:91)
           at org.jboss.seam.ui.converter.EntityConverterStore_$$_javassist_0.put(EntityConverterStore_$$_javassist_0.java)
           at org.jboss.seam.ui.converter.EntityConverter.getAsString(EntityConverter.java:67)
           at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getFormattedValue(HtmlBasicRenderer.java:469)
           at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOption(MenuRenderer.java:502)
           at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:757)
           at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:811)
           at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:335)
           at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:896)
           at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
           at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
           at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
           at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
           at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
           at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
           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.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
           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.MultipartFilter.doFilter(MultipartFilter.java:85)
           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:44)
           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:179)
           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(Thread.java:595)
          


          • 2. Re: selectOneMenu - NPE
            Marius Oancea Novice

            Please post the whole NPE exception.

            Are you sure questionCategoryList is outjected?

            • 3. Re: selectOneMenu - NPE
              Marius Oancea Novice

              Ah. I posted my message before you posted the exception.

              Anyway: please make sue you are using the entityManager (and is named entityManager). This seems correct according to your posted XML.

              Your entity has to have a @Id. Make sure of that.

              NPE seems to be at
              EntityIdentifier key = new EntityIdentifier(entity, getEntityManager());

              Eventually make a brackpoint here and see what is null.

              • 4. Re: selectOneMenu - NPE
                Pete Muir Master

                Which version of Seam?

                • 5. Re: selectOneMenu - NPE
                  Bartosz Jamroz Newbie

                  @Pete
                  Seam 2.0.0.GA

                  @Marius
                  Yes I`m sure that questionCategoryList is outjected. Anyway, this code works on Seam 1.2.1.GA...

                  questionCategory entity

                  @Entity
                  @Scope(ScopeType.EVENT)
                  @Name("questionCategory")
                  @Table(name="QuestionCategories")
                  public class QuestionCategory implements Serializable {
                  
                   @Id @GeneratedValue
                   private Long id;
                  
                   @NotNull @Length(min=3, max=100)
                   private String categoryName;
                  
                   @OneToMany @JoinColumn(name="category_id")
                   private List<Question> questionList;
                  
                   @Temporal(value = TemporalType.TIMESTAMP)
                   private Date created;
                  
                   @Override
                   public boolean equals(Object obj) {
                   if (!(obj instanceof QuestionCategory) || this.id == null) {
                   return false;
                   }
                  
                   return this.id.equals(((QuestionCategory)obj).getId());
                   }
                  
                   public QuestionCategory() {
                   this.questionList = new ArrayList<Question>();
                   }
                  
                   public QuestionCategory(String categoryName) {
                   this.categoryName = categoryName;
                   this.questionList = new ArrayList<Question>();
                   }
                  
                   public Long getId() {
                   return id;
                   }
                  
                   public void setId(Long id) {
                   this.id = id;
                   }
                  
                   public String getCategoryName() {
                   return categoryName;
                   }
                  
                   public void setCategoryName(String categoryName) {
                   this.categoryName = categoryName;
                   }
                  
                   public List<Question> getQuestionList() {
                   return questionList;
                   }
                  
                   public void setQuestionList(List<Question> questionList) {
                   this.questionList = questionList;
                   }
                  
                   public Date getCreated() {
                   return created;
                   }
                  
                   public void setCreated(Date created) {
                   this.created = created;
                   }
                  }
                  



                  • 6. Re: selectOneMenu - NPE
                    Daniel Hinojosa Master

                    1. What does the bean that generates questionCategoryList look like?

                    • 7. Re: selectOneMenu - NPE
                      Bartosz Jamroz Newbie

                       

                      @Stateful
                      @Scope(ScopeType.SESSION)
                      @Name("QuestionCategoryController")
                      public class QuestionCategoryControllerBean implements QuestionCategoryController {
                      
                       @Logger
                       private Log log;
                      
                       @In(create = true)
                       private QuestionCategoryManager questionCategoryManager;
                      
                       @DataModel
                       private List<QuestionCategory> questionCategoryList;
                      
                       @In(create = true)
                       @DataModelSelection
                       private QuestionCategory questionCategory;
                      
                       public void addCategory() {
                       log.info("Adding category [#{questionCategory.categoryName}]");
                       questionCategoryManager.addCategory(questionCategory);
                       getAllQuestionsCategories();
                       }
                      
                       public void removeCategory() {
                       questionCategoryList.remove(questionCategory);
                       questionCategoryManager.removeCategory(questionCategory);
                       questionCategory = null;
                       getAllQuestionsCategories();
                       }
                      
                       @Factory(value="questionCategoryList")
                       public void getAllQuestionsCategories() {
                       questionCategoryList = questionCategoryManager.getAllQuestionCategories();
                       }
                      
                       @Remove @Destroy
                       public void destroy() {}
                       }
                      


                      Session context
                       QuestionCategoryController
                      QuestionController
                      facelets.ui.DebugOutput
                      javax.faces.request.charset
                      org.jboss.seam.core.conversationEntries
                      org.jboss.seam.international.localeSelector
                      org.jboss.seam.international.timeZoneSelector
                      org.jboss.seam.security.identity
                      org.jboss.seam.web.session
                      questionCategoryList
                      


                      • 8. Re: selectOneMenu - NPE
                        Bartosz Jamroz Newbie

                        anybody ?

                        • 9. Re: selectOneMenu - NPE
                          Pete Muir Master

                          If you can create a runnable example and provide steps to reproduce please put an issue into JIRA so I can take a look.