4 Replies Latest reply on Nov 21, 2007 12:15 AM by Siobhan Ernest

    selectOneMenu - NullPointerException

    Siobhan Ernest Newbie

      Hello -

      I am trying to implement a dropdown on a form and getting a NullPointerException during the render phase:

      xhtml snippet:

       <h:selectOneMenu id="selectedUploadDefinition" value="#{uploadService.selectedUploadDefinition}">
       <s:selectItems
       value="#{uploadDefinitions}"
       var="ud"
       label="#{ud.name}"
       noSelectionLabel="Please Select..."/>
       <s:convertEntity/>
       </h:selectOneMenu>
      


      action snippet:

      @Stateful
      @Name("uploadService")
      @Scope(ScopeType.EVENT)
      @Restrict("#{identity.loggedIn}")
      public class UploadAction implements Upload {
      
       @Logger
       Log log;
      
       @PersistenceContext
       private EntityManager em;
      
       private byte[] data;
       private String contentType;
       private String fileName;
       private int size;
      
       @Out(required = false)
       private List<UploadDefinition> uploadDefinitions;
      
       private UploadDefinition selectedUploadDefinition ;
      
      
       @Factory("uploadDefinitions")
       public void loadUploadDefinitions() {
       log.info("UPLOAD SERVICE: loading uploadDefinitions for upload action");
       uploadDefinitions = em.createQuery(
       "select ud from UploadDefinition ud order by ud.name")
       .getResultList();
       log.info("RESULT SIZE: " + uploadDefinitions.size());
       }
      
       public List<UploadDefinition> getUploadDefinitions() {
       return uploadDefinitions;
       }


      entity :

      @Entity
      public class UploadDefinition implements Serializable {
       private long uoid;
       private String name ;
       private String headers ;
       private List<ImportField> importFields ;
      
       public UploadDefinition() {
       }
      
       public UploadDefinition(String name, String headers) {
       this.name = name;
       this.headers = headers;
       }
      
       public UploadDefinition(long uoid, String name, String headers) {
       this.uoid = uoid;
       this.name = name;
       this.headers = headers ;
       }
      
       @Id @GeneratedValue
       public long getUoid() {
       return uoid;
       }
      
       public void setUoid(long uoid) {
       this.uoid = uoid;
       }
      
       @Column(name = "name", unique = true)
       public String getName() {
       return name;
       }
      
       public void setName(String name) {
       this.name = name;
       }
      
       @Length(max=512)
       public String getHeaders() {
       return headers;
       }
      
       public void setHeaders(String headers) {
       this.headers = headers;
       }
      
       @OneToMany(mappedBy = "uploadDefinition", fetch=FetchType.EAGER)
       @OrderBy("value")
       public List<ImportField> getImportFields() {
       return importFields;
       }
      
       public void setImportFields(List<ImportField> importFields) {
       this.importFields = importFields;
       }
      }



      stacktrace:

      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:597)
       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_2.put(EntityConverterStore_$$_javassist_2.java)
       at org.jboss.seam.ui.converter.EntityConverter.getAsString(EntityConverter.java:67)
       at org.jboss.seam.ui.converter.PrioritizableConverter.getAsString(PrioritizableConverter.java:67)
       at org.jboss.seam.ui.converter.ConverterChain.getAsString(ConverterChain.java:123)
       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 org.jboss.seam.ui.util.cdk.RendererBase.renderChild(RendererBase.java:190)
       at org.jboss.seam.ui.util.cdk.RendererBase.renderChildren(RendererBase.java:166)
       at org.jboss.seam.ui.renderkit.ValidateAllRendererBase.doEncodeChildren(ValidateAllRendererBase.java:33)
       at org.jboss.seam.ui.util.cdk.RendererBase.encodeChildren(RendererBase.java:92)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
       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 org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
       at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
       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.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.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
       at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
       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.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
       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:619)


      Using Seam 2.0.0GA and JBoss 4.2.2GA

      Any ideas what I am doing wrong?

        • 1. Re: selectOneMenu - NullPointerException
          Pete Muir Master

          Post your components.xml - you need to use a SMPC with s:convertEntity

          • 2. Re: selectOneMenu - NullPointerException
            Chris Malan Novice

            I don't know if I have a Seam Managed Persistence Context in my components.xml. I'm mailing this from work. But I at last did get s:selectItems to work.

            What did the trick was that every @entity that is used as a source for s:selectItems must implement a "boolean equals(Object obj)" and an "int hashCode()" method. Make sure about this last one, maybe it's getHashCode or something similar.

            Give it a go.

            • 3. Re: selectOneMenu - NullPointerException
              Andy Gibson Newbie

              Pete, since he is using @PersistenceContext, doesn't that rule out the possibility of using an SMPC?

              This PC is only scoped to the event, after which it is unavailable. I've been having a null filled list problem recently and I think (haven't had time to check) that it is tied to the PC flushing and invalidating objects (based on my late night reading of JPA with Hibernate).


              • 4. Re: selectOneMenu - NullPointerException
                Siobhan Ernest Newbie

                Hi all -

                I actually scrapped this code and changed it to the following:

                components.xml

                <persistence:managed-persistence-context name="entityManager"
                 auto-create="true"
                 persistence-unit-jndi-name="java:/rte_trackerEntityManagerFactory"/>


                plus a list seam-gen generated list bean:

                @Name("uploadDefinitionList")
                public class UploadDefinitionList extends EntityQuery {
                
                 private static final String[] RESTRICTIONS = {
                 "lower(uploadDefinition.name) like concat(lower(#{uploadDefinitionList.uploadDefinition.name}),'%')",
                 "lower(uploadDefinition.headers) like concat(lower(#{uploadDefinitionList.uploadDefinition.headers}),'%')",
                 "lower(uploadDefinition.matchOn) like concat(lower(#{uploadDefinitionList.uploadDefinition.matchOn}),'%')",
                 "lower(uploadDefinition.uploadType) like concat(lower(#{uploadDefinitionList.uploadDefinition.uploadType}),'%')",};
                
                 private UploadDefinition uploadDefinition = new UploadDefinition();
                
                 @Override
                 public String getEjbql() {
                 return "select uploadDefinition from UploadDefinition uploadDefinition";
                 }
                
                 @Override
                 public Integer getMaxResults() {
                 return 25;
                 }
                
                 public UploadDefinition getUploadDefinition() {
                 return uploadDefinition;
                 }
                
                 @Override
                 public List<String> getRestrictions() {
                 return Arrays.asList(RESTRICTIONS);
                 }
                
                }


                The upload action:

                public abstract class EntityUploadAction {
                 @Logger
                 Log log;
                
                 @PersistenceContext
                 protected EntityManager entityManager;
                
                 @In
                 protected FacesMessages facesMessages;
                
                
                 <snip>
                
                
                 protected UploadDefinition selectedUploadDefinition;
                
                
                 <snip>
                
                 public UploadDefinition getSelectedUploadDefinition() {
                 return selectedUploadDefinition;
                 }
                
                 public void setSelectedUploadDefinition(UploadDefinition selectedUploadDefinition) {
                 this.selectedUploadDefinition = selectedUploadDefinition;
                 }
                
                 <snip>
                }


                The upload action is used more than once, so this is extended in other actions.

                And finally, the .xhtml

                <s:decorate id="selectedUploadDefinitionnDecoration" template="layout/edit.xhtml">
                 <ui:define name="label">Upload Definition</ui:define>
                 <h:selectOneMenu value="#{studentUploadService.selectedUploadDefinition}" required="true"
                 id="selectedUploadDefinition">
                 <s:selectItems value="#{uploadDefinitionList}" var="ud" label="#{ud.name}"
                 noSelectionLabel="Please Select..."/>
                 <s:convertEntity/>
                 </h:selectOneMenu>
                 </s:decorate>




                It all works, and I am happy - just posting this for anyone who might be interested.