3 Replies Latest reply on Nov 17, 2008 12:43 PM by Tamas Malatinszki

    s:convertEntity throws NullPointerException

    Tamas Malatinszki Newbie

      Hi All,


      I would like to use s:convertEntity in my h:selectOneListBox, but when I'm calling my page it returns with NullPointerException.


      This is my components.xml:


      <?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
                              xmlns:core="http://jboss.com/products/seam/core"
                  xmlns:persistence="http://jboss.com/products/seam/persistence"
                  xmlns:security="http://jboss.com/products/seam/security"
                  xmlns:transaction="http://jboss.com/products/seam/transaction"
                  xmlns:mail="http://jboss.com/products/seam/mail"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                              xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
                                                      http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
                                                      http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                                                      http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.0.xsd
                                                      http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd
                                                      http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd">
       
       <core:init debug="true" jndi-pattern="@jndiPattern@"/>
       
        <persistence:hibernate-session-factory name="hibernateSessionFactory"/>
        <persistence:managed-hibernate-session name="drsession"
                                                                        auto-create="true"
                                                           session-factory="#{hibernateSessionFactory}"
                                          session-factory-jndi-name="java:/directreportsSessionFactory"/>
       
        <transaction:hibernate-transaction session="#{drsession}"/>
       
        <component name="org.jboss.seam.ui.converter.EntityConverter" scope="SESSION">
          <property name="session">#{drsession}</property>
        </component>
       
      </components> 




      This is my entity called Source:


      @Entity
      @Name("source")
      @Table(name="sources")
      public class Source implements Serializable {
      
              private static final long serialVersionUID = 1L;
      
              @Id
              @Column(name = "sourceid")
              @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="sources_sourceid_seq")
              @SequenceGenerator(name="sources_sourceid_seq", sequenceName="sources_sourceid_seq", allocationSize=1)
              private Integer sourceid;
              
              @Column(name = "source", unique = false, nullable = false)
              private String source;
      
              
              public Source() {
                      super();
              }
      
              public Source(Integer sourceid, String source) {
                      super();
                      this.sourceid = sourceid;
                      this.source = source;
              }
      
              public Integer getSourceId() {
                      return sourceid;
              }
      
              public void setSourceId(Integer sourceid) {
                      this.sourceid = sourceid;
              }
      
              public String getSource() {
                      return source;
              }
      
              public void setSource(String source) {
                      this.source = source;
              }
              
      }



      And this is my action bean:



      @Startup
      @Stateful
      @Name("hireAction")
      @Scope(ScopeType.SESSION)
      public class HireActionImpl implements HireAction {
      
              @In
              private Session drsession;
      
              @DataModel
              private List<Source> sourceList;
              
              @DataModelSelection(value="sourceList")
              @Out(required=false, value="selectedSource")
              private Source selectedSource;
      
              @Create
              public void init(){
                      this.sourceList=new ArrayList<Source>();
                      this.selectedSource=new Source();
              }
      
              //GETTERS & SETTERS
      }



      This is the part of the xhtml page where I'm using s:convertEntity:



      <h:selectOneListbox id="sourceListBox" value="#{selectedSource}" size="1">
        <s:selectItems id="sourceItems" value="#{sourceList}" var="sss" label="#{sss.source}"/>
        <s:convertEntity/>
      </h:selectOneListbox>



      When I'm calling this page I'm receiving this error message:



      13:46:14,334 ERROR [STDERR] Nov 7, 2008 1:46:14 PM com.sun.facelets.FaceletViewHandler handleRenderException
      SEVERE: Error Rendering View[/pages/main.xhtml]
      java.lang.NullPointerException
              at org.jboss.seam.persistence.HibernatePersistenceProvider.getSession(HibernatePersistenceProvider.java:355)
              at org.jboss.seam.persistence.HibernatePersistenceProvider.getId(HibernatePersistenceProvider.java:163)
              at org.jboss.seam.framework.EntityIdentifier.<init>(EntityIdentifier.java:13)
              at org.jboss.seam.ui.JpaEntityLoader.createIdentifier(JpaEntityLoader.java:29)
              at org.jboss.seam.ui.AbstractEntityLoader.put(AbstractEntityLoader.java:46)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              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:28)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:40)
              at org.jboss.seam.util.Work.workInTransaction(Work.java:47)
              at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:34)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
              at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
              at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
              at org.jboss.seam.ui.JpaEntityLoader_$$_javassist_4.put(JpaEntityLoader_$$_javassist_4.java)
              at org.jboss.seam.ui.EntityConverter.getAsString(EntityConverter.java:67)
              at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getFormattedValue(HtmlBasicRenderer.java:448)
              at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOption(MenuRenderer.java:480)
              at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:768)
              at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:828)
              at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:280)
              at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
              at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:242)
              at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:178)
              at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:126)
              at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
              at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
              at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
              at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:220)
              at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:215)
              at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:121)
              at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
              at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
              at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
              at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:284)
              at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
              at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:284)
              at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
              at org.richfaces.renderkit.TabRendererBase.encodeChildren(TabRendererBase.java:113)
              at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
              at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
              at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
              at org.richfaces.renderkit.html.TabPanelRenderer.doEncodeChildren(TabPanelRenderer.java:286)
              at org.richfaces.renderkit.html.TabPanelRenderer.doEncodeChildren(TabPanelRenderer.java:281)
              at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:121)
              at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
              at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
              at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
              at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:220)
              at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:215)
              at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:121)
              at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
              at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
              at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
              at org.ajax4jsf.renderkit.html.AjaxOutputPanelRenderer.encodeChildren(AjaxOutputPanelRenderer.java:78)
              at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
              at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
              at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:124)
              at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:67)
              at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:115)
              at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:67)
              at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:115)
              at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:67)
              at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:115)
              at org.ajax4jsf.renderkit.AjaxContainerRenderer.encodeAjax(AjaxContainerRenderer.java:123)
              at org.ajax4jsf.component.AjaxViewRoot.encodeAjax(AjaxViewRoot.java:677)
              at org.ajax4jsf.component.AjaxViewRoot.encodeChildren(AjaxViewRoot.java:548)
              at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
              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:196)
              at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:109)
              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
              at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
              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.IdentityFilter.doFilter(IdentityFilter.java:38)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
              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:45)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      13:46:14,334 ERROR [STDERR] 
              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
              at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
              at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
              at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
              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:51)
              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:182)
              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(Unknown Source)



      If I'm removing the s:convertEntity tag it's working fine (but of course it not converts my Source entity).
      I'm using JBoss 4.2.3 and Seam 2.1 GA (I tested it with Seam 2.1 SP1 and Seam 2.0.2, but the result was the same).


      Is there anyone who has anu idea about this issue?


      Thanks,
      Tamas

        • 1. Re: s:convertEntity throws NullPointerException
          Alram Lechner Newbie

          hi tamas,


          i have exact the same problem. (same jboss and seam version, same exception)


          did you find any solution?


          thanks!

          • 2. Re: s:convertEntity throws NullPointerException
            Tamas Malatinszki Newbie

            Hi Alram


            Yes, I've found the root cause of the issue: there are a few things that changed in Seam 2.1, so if You want to use the s:convertEntity You need to change components.xml to something like this:



            <?xml version="1.0" encoding="UTF-8"?>
            <components xmlns="http://jboss.com/products/seam/components"
                            xmlns:core="http://jboss.com/products/seam/core"
                        xmlns:persistence="http://jboss.com/products/seam/persistence"
                        xmlns:security="http://jboss.com/products/seam/security"
                        xmlns:ui="http://jboss.com/products/seam/ui"
                        xmlns:transaction="http://jboss.com/products/seam/transaction"
                        xmlns:mail="http://jboss.com/products/seam/mail"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                            xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
                                                 http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
                                                 http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                                                 http://jboss.com/products/seam/ui http://jboss.com/products/seam/ui-2.1.xsd
                                                 http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd
                                                 http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd
                                                 http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd">
             
              <core:init debug="true" jndi-pattern="@jndiPattern@"/> 
              <core:manager conversation-timeout="120000" 
                            concurrent-request-timeout="500"
                            conversation-id-parameter="cid"/>
            
              <persistence:hibernate-session-factory name="hibernateSessionFactory"/>
              <persistence:managed-hibernate-session name="hibernateSession"
                                                        auto-create="true"
                                                              scope="session"
                                                 session-factory="#{hibernateSessionFactory}"/>
              <transaction:hibernate-transaction session="#{hibernateSession}"/>
              <transaction:ejb-transaction/> 
              <ui:hibernate-entity-loader session="#{hibernateSession}"/>
            
            </components>



            It was my fault, I still used the Seam 2.0.x reference guide while I started to use Seam 2.1.x, because I didn't think that this part is not compatible anyway with the old versions....beginners mistake. :)


            Please let me know if this solution is working fine for You.


            Regards,
            Tamas

            • 3. Re: s:convertEntity throws NullPointerException
              Tamas Malatinszki Newbie

              Hi Alram


              Yes, I've found the root cause of the issue: there are a few things that changed in Seam 2.1, so if You want to use the s:convertEntity You need to change components.xml to something like this:



              <?xml version="1.0" encoding="UTF-8"?>
              <components xmlns="http://jboss.com/products/seam/components"
                              xmlns:core="http://jboss.com/products/seam/core"
                          xmlns:persistence="http://jboss.com/products/seam/persistence"
                          xmlns:security="http://jboss.com/products/seam/security"
                          xmlns:ui="http://jboss.com/products/seam/ui"
                          xmlns:transaction="http://jboss.com/products/seam/transaction"
                          xmlns:mail="http://jboss.com/products/seam/mail"
                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                              xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
                                                   http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
                                                   http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                                                   http://jboss.com/products/seam/ui http://jboss.com/products/seam/ui-2.1.xsd
                                                   http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd
                                                   http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd
                                                   http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd">
               
                <core:init debug="true" jndi-pattern="@jndiPattern@"/> 
                <core:manager conversation-timeout="120000" 
                              concurrent-request-timeout="500"
                              conversation-id-parameter="cid"/>
              
                <persistence:hibernate-session-factory name="hibernateSessionFactory"/>
                <persistence:managed-hibernate-session name="hibernateSession"
                                                          auto-create="true"
                                                                scope="session"
                                                   session-factory="#{hibernateSessionFactory}"/>
                <transaction:hibernate-transaction session="#{hibernateSession}"/>
                <transaction:ejb-transaction/> 
                <ui:hibernate-entity-loader session="#{hibernateSession}"/>
              
              </components>



              It was my fault, I still used the Seam 2.0.x reference guide while I started to use Seam 2.1.x, because I didn't think that this part is not compatible anyway with the old versions....beginners mistake. :)


              Please let me know if this solution is working fine for You.


              Regards,
              Tamas