4 Replies Latest reply on Aug 27, 2009 3:14 PM by Casey Boyd

    Newbie needs help with s:convertEntity

    Casey Boyd Newbie

      Can someone please help me with a very simple example using s:convertEntity?


      Here is what I have....


      components.xml




              <persistence:hibernate-session-factory name="hibernateSessionFactory" />
      
           <persistence:managed-hibernate-session name="ifnDatabase" auto-create="true" session-factory-jndi-name="java:/ifnSessionFactory" />
           
           <transaction:hibernate-transaction session="#{ifnDatabase}" /> 
        
             <ui:hibernate-entity-loader session="#{ifnDatabase}"/>



      Action Bean




      @Name("getserviceproviders")
      @Scope(ScopeType.PAGE)
      public class GetServiceProvidersAction {
      
       public List<ServiceProvider> getServiceProviders(){ 
      
      ...
      
      }
      
      }




      Bean




      @Entity
      public class ServiceProvider implements Serializable {
      
      ...
      
      }




      xhtml



      <h:selectOneMenu id="selMenServiceProviders" >
                                  
                                  <s:selectItems value="#{getserviceproviders.serviceProviders}" 
                                                    var="sp" 
                                                    label="#{sp.name}" 
                                                    noSelectionLabel="Select Service Provider...." />
       
                                  <s:convertEntity />
                             
                          </h:selectOneMenu>  



       
      Something is configured or set up wrong....


      ANY help would be appreciated....


      thanks


      indy





        • 1. Re: Newbie needs help with s:convertEntity
          Arbi Sookazian Master
          <h:selectOneMenu  id="newStatusMenu"
                                                                                     value="#{equipmentProcessingView.selectedListValueForNewStatus}" 
                                                                                  required="true">  
                                                                      <s:selectItems var="lve" 
                                                                                        value="#{populateDropDown.getListValueList('Recovery_Status')}"     
                                                                                        label="#{lve.description}"
                                                                                        noSelectionLabel="Please Select..."/>
                                                                      <s:convertEntity/>
                                                                                                     
                                                                 </h:selectOneMenu>     



          @Name("equipmentProcessingView")
          @Scope(ScopeType.CONVERSATION)
          @ProfilingThisClass
          //@Transactional
          public class EquipmentProcessingViewAction implements Serializable {
              private ListValue selectedListValueForNewStatus;
          ...
          public ListValue getSelectedListValueForNewStatus() {
                    return selectedListValueForNewStatus;
               }
          
               public void setSelectedListValueForNewStatus(ListValue selectedListValueForNewStatus) {
                    this.selectedListValueForNewStatus = selectedListValueForNewStatus;
               }
          
          



          @Name("populateDropDown")
          @AutoCreate
          @Scope(ScopeType.CONVERSATION)
          @Transactional
          public class PopulateDropDown implements Serializable {
               
               private static final long serialVersionUID = -8836664905031033539L;
          
               //retrieve all labels/values for a particular drop down
               @Logger
               private Log log;
               
               @In
               private EntityManager entityManager;
                    
               private List<ListValue> listValueList;
               
               @SuppressWarnings("unchecked")
               public List<ListValue> getListValueList(String listName)
               {     
                    listValueList = entityManager.createQuery(  " select lv "+
                                                                                " from ListValue lv, "+
                                                                                " List l "+
                                                                                " where lv.list.listId = l.listId "+
                                                                                " and l.listName = :listName "+
                                                                                " order by lv.sortId ")
                                                             .setParameter("listName", listName)
                                                             .getResultList();
                    
                    log.info("in getListValueList: listValueList.size() = " + listValueList.size());
                    
                    return listValueList;
               }
               
               @SuppressWarnings("unchecked")
               public ListValue getListValue(String listName, Integer listCode)
               {     
                    listValueList = entityManager.createQuery(  " select lv "+
                                                                                " from ListValue lv, "+
                                                                                " List l "+
                                                                                " where lv.list.listId = l.listId "+
                                                                                " and l.listName = :listName "+
                                                                                " and lv.code = :listCode")
                                                             .setParameter("listName", listName)
                                                             .setParameter("listCode", listCode)
                                                             .getResultList();
                    
                    ListValue lve = null;
                    
                    if (listValueList != null && listValueList.size() > 0)
                    {
                         lve = listValueList.get(0);
                         log.info("in getListValue: getListValue.getDescription() = " + lve.getDescription());
                    }
                    
                    return lve;
               }
               
          
          }
          

          • 2. Re: Newbie needs help with s:convertEntity
            Casey Boyd Newbie

            When I try the code....I get....




            java.lang.NullPointerException
                 at org.jboss.seam.persistence.HibernatePersistenceProvider.getSession(HibernatePersistenceProvider.java:369)
                 at org.jboss.seam.persistence.HibernatePersistenceProvider.getId(HibernatePersistenceProvider.java:177)
                 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:32)
                 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:97)
                 at org.jboss.seam.util.Work.workInTransaction(Work.java:47)
                 at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91)
                 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:185)
                 at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
                 at org.jboss.seam.ui.JpaEntityLoader_$$_javassist_seam_7.put(JpaEntityLoader_$$_javassist_seam_7.java)
                 at org.jboss.seam.ui.EntityConverter.getAsString(EntityConverter.java:65)
                 at org.jboss.seam.ui.converter.PrioritizableConverter.getAsString(PrioritizableConverter.java:67)
                 at org.jboss.seam.ui.converter.ConverterChain.getAsString(ConverterChain.java:126)
                 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:772)
                 at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:832)
                 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:180)
                 at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:127)
                 at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
                 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
                 at javax.faces.render.Renderer.encodeChildren(Renderer.java:148)
                 at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
                 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
                 at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
                 at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
                 at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
                 at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
                 at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
                 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:40)
                 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)
                 at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                 at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                 at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
                 at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
                 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:60)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                 at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
                 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.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                 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:235)
                 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                 at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
                 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
                 at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
                 at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
                 at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
                 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:158)
                 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
                 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
                 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
                 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                 at java.lang.Thread.run(Unknown Source)




            • 3. Re: Newbie needs help with s:convertEntity
              Arbi Sookazian Master

              You need to carefully examine the Seam booking example project, or another example project in the distro, that uses s:convertEntity for an example.


              Did you use seam-gen to create your project skeleton?


              The NPE is happening here in org.jboss.seam.persistence.HibernatePersistenceProvider:


              private Session getSession(EntityManager entityManager)
                 {
                    Object delegate = entityManager.getDelegate();  //<-- NPE here!
                    if ( delegate instanceof Session )
                    {
                       return (Session) delegate;
                    }
                    else
                    {
                       throw new NotHibernateException();
                    }
                 }



              I'm not sure why this is happening but most likely you need to check your config files (e.g. components.xml, *-ds.xml, persistence.xml, etc.)


              Remember, if you have to you can add debug breakpoints in Eclipse and step thru the Seam core code...

              • 4. Re: Newbie needs help with s:convertEntity
                Casey Boyd Newbie

                I got it....thanks so much for your help...


                First, I was trying to set up my components.xml for the wrong version of Seam. I was following directions for 2.0 when I was running 2.1.2.


                Second, and I probably missed this, but you must return a list of objects from your Hibernate session when populating the select items. Which makes sense, but I didn't fully get this at first....


                For exammple....


                This will NOT work...



                function List<User> getUsers() {
                
                     List<Users> userList = new ArrayList<User>();
                
                     userList.add(new User("bob"));
                
                     return userList;
                }



                This will work....




                function List<User> getUsers() {
                
                     Criteria criteria = hibernateSession.createCriteria(User.class);
                
                     List userList = criteria.list();
                
                     return userList;
                }




                Is that correct?


                I know I can make a custom converter, but if you are going to use s:convertEntity, you need to make sure you use your Hibernate Session to create the list of objects....


                Or am I missing something totally here?