9 Replies Latest reply on Oct 4, 2007 3:39 PM by griffitm

    Simple selectOneMenu Example/seamgen

    griffitm

      Hi All,

      I am coming from a struts back ground, and I am lost for where to start trying to debug this problem. I have an Object (Delivery) with an association from a pick list (Status)

      I created a seam-gen project and played around with it, but I don't want to have to navigate to a different web page just to pick the status for my delivery. I want to provide a DDLB on the delivery edit page, and allow the user to select from a list that is in the status DB. Seems simple enough, in Struts I'd simply put this list into a context and reference it. What I did in Seam may not be right.

      In the components.xml file, I defined a framework query like this:

      <framework:entity-query name="allStatus"
       entity-manager="#{em}"
       ejbql="select s from Status s"
       order="s.description"/>


      Then I reference it in my xhtml file as follows:
      <s:decorate id="statusDecoration" template="layout/edit.xhtml">
       <ui:define name="label">status</ui:define>
       <h:selectOneMenu id="status" value="#{deliverableHome.instance.status}">
       <s:convertEntity />
       <s:selectItems value="#{allStatus.resultList}"
       var="deliverableHome.instance.status"
       label="#{status.description}"/>
       </h:selectOneMenu>
       </s:decorate>


      The list of status codes show up in a drop down list, but when I try to save the record, I get an HBM mapping error:

      java.lang.IllegalArgumentException: Unknown entity: gov.hhs.fda.ocio.fdaaa.entity.Status_$$_javassist_39
       at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:185)
       at org.jboss.seam.persistence.EntityManagerProxy.find(EntityManagerProxy.java:85)
       at org.jboss.seam.framework.EntityIdentifier.find(EntityIdentifier.java:26)
       at org.jboss.seam.ui.converter.EntityConverterStore.get(EntityConverterStore.java:43)
       at org.jboss.seam.ui.converter.EntityConverter.getAsObject(EntityConverter.java:81)
       at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:152)
       at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(MenuRenderer.java:197)
       at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:359)
       at javax.faces.component.UIInput.getConvertedValue(UIInput.java:934)
       at javax.faces.component.UIInput.validate(UIInput.java:860)
       at javax.faces.component.UIInput.executeValidate(UIInput.java:1065)
       at javax.faces.component.UIInput.processValidators(UIInput.java:666)
       at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1033)
       at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1033)
       at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1033)
       at javax.faces.component.UIForm.processValidators(UIForm.java:229)
       at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1033)
       at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:662)
       at org.ajax4jsf.framework.ajax.AjaxViewRoot.access$201(AjaxViewRoot.java:53)
       at org.ajax4jsf.framework.ajax.AjaxViewRoot$3.invokeRoot(AjaxViewRoot.java:315)
       at org.ajax4jsf.framework.ajax.JsfOneOneInvoker.invokeOnRegionOrRoot(JsfOneOneInvoker.java:53)
       at org.ajax4jsf.framework.ajax.AjaxContext.invokeOnRegionOrRoot(AjaxContext.java:191)
       at org.ajax4jsf.framework.ajax.AjaxViewRoot.processValidators(AjaxViewRoot.java:329)
       at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:100)
       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
       at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
       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:63)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:87)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:63)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:46)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
       at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)
       at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:40)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:140)
       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.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
       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:241)
       at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:853)
       at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
       at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1513)
       at java.lang.Thread.run(Thread.java:595)
      Caused by: org.hibernate.MappingException: Unknown entity: gov.hhs.fda.ocio.fdaaa.entity.Status_$$_javassist_39
       at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:550)
       at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:68)
       at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
       at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
       at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
       at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:174)
       ... 61 more
      16:58:10,180 WARN [lifecycle] executePhase(PROCESS_VALIDATIONS 3,com.sun.faces.context.FacesContextImpl@1124609) threw
      exception
      javax.faces.FacesException: Unknown entity: gov.hhs.fda.ocio.fdaaa.entity.Status_$$_javassist_39
       at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:108)
       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
       at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
       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:63)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:87)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:63)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:46)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
       at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)
       at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:40)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:140)
       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.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
       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:241)
       at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:853)
       at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
       at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1513)
       at java.lang.Thread.run(Thread.java:595)
      Caused by: java.lang.IllegalArgumentException: Unknown entity: gov.hhs.fda.ocio.fdaaa.entity.Status_$$_javassist_39
       at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:185)
       at org.jboss.seam.persistence.EntityManagerProxy.find(EntityManagerProxy.java:85)
       at org.jboss.seam.framework.EntityIdentifier.find(EntityIdentifier.java:26)
       at org.jboss.seam.ui.converter.EntityConverterStore.get(EntityConverterStore.java:43)
       at org.jboss.seam.ui.converter.EntityConverter.getAsObject(EntityConverter.java:81)
       at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:152)
       at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(MenuRenderer.java:197)
       at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:359)
       at javax.faces.component.UIInput.getConvertedValue(UIInput.java:934)
       at javax.faces.component.UIInput.validate(UIInput.java:860)
       at javax.faces.component.UIInput.executeValidate(UIInput.java:1065)
       at javax.faces.component.UIInput.processValidators(UIInput.java:666)
       at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1033)
       at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1033)
       at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1033)
       at javax.faces.component.UIForm.processValidators(UIForm.java:229)
       at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1033)
       at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:662)
       at org.ajax4jsf.framework.ajax.AjaxViewRoot.access$201(AjaxViewRoot.java:53)
       at org.ajax4jsf.framework.ajax.AjaxViewRoot$3.invokeRoot(AjaxViewRoot.java:315)
       at org.ajax4jsf.framework.ajax.JsfOneOneInvoker.invokeOnRegionOrRoot(JsfOneOneInvoker.java:53)
       at org.ajax4jsf.framework.ajax.AjaxContext.invokeOnRegionOrRoot(AjaxContext.java:191)
       at org.ajax4jsf.framework.ajax.AjaxViewRoot.processValidators(AjaxViewRoot.java:329)
       at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:100)
       ... 38 more
      Caused by: org.hibernate.MappingException: Unknown entity: gov.hhs.fda.ocio.fdaaa.entity.Status_$$_javassist_39
       at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:550)
       at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:68)
       at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
       at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
       at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
       at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:174)
       ... 61 more


      This makes no sense to me. Am I going about this the wrong way?

      Any help would be much appreciated.

      Cheers!


        • 1. Re: Simple selectOneMenu Example/seamgen
          damianharvey

          Your approach is certainly correct. Show your code for deliverableHome. Does it use the same 'Status' class as the entityQuery?

          Is gov.hhs.fda.ocio.fdaaa.entity.Status the correct package?

          Cheers,

          Damian

          • 2. Re: Simple selectOneMenu Example/seamgen
            griffitm

            Damian,

            Thanks for the reply. I thought I was on the right track from looking at this related link: http://wiki.jboss.org/wiki/Wiki.jsp?page=SeamEntityConverter

            Here is my deliverableHome class:

            package gov.hhs.fda.ocio.fdaaa.entity;
            
            import org.jboss.seam.annotations.In;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.framework.EntityHome;
            
            @Name("deliverableHome")
            public class DeliverableHome extends EntityHome<Deliverable> {
            
             @In(create = true)
             StatusHome statusHome;
            
             public void setDeliverableId(Integer id) {
             setId(id);
             }
            
             public Integer getDeliverableId() {
             return (Integer) getId();
             }
            
             @Override
             protected Deliverable createInstance() {
             Deliverable deliverable = new Deliverable();
             return deliverable;
             }
            
             public void wire() {
             Status status = statusHome.getDefinedInstance();
             if (status != null) {
             getInstance().setStatus(status);
             }
             }
            
             public boolean isWired() {
             if (getInstance().getType() == null)
             return false;
             if (getInstance().getStatus() == null)
             return false;
             if (getInstance().getConsequence() == null)
             return false;
             return true;
             }
            
             public Deliverable getDefinedInstance() {
             return isIdDefined() ? getInstance() : null;
             }
            
            }
            


            As for the right package, I believe so. It was all generated by seamgen. Does the entity-query need to specify the entire package? I tend to think this is a problem with mapping to the deliverableHome.status property. I have 2 records in the status table which looks like this:
            ID Description
            1 In-Progress
            2 On-Hold
            


            I set the status_id to 2, and when I bring up the record to edit it, the status selected in the select box is 1, In-Progress. In the struts world, this would tell me that the HTML fragment generated doesn't match the struts bean mapped to the action.

            Any thoughts?

            Thanks in advance!

            • 3. Re: Simple selectOneMenu Example/seamgen
              griffitm

              Ok, I got the problem sorted.

              The problem was that I had the convertEntity tag before selectOneMenu. The solution was to move it AFTER the selectOneMenu, thusly:

               <s:decorate id="statusDecoration" template="layout/edit.xhtml">
               <ui:define name="label">status</ui:define>
               <h:selectOneMenu id="status" value="#{deliverableHome.instance.status}">
               <s:selectItems value="#{allStatus.resultList}"
               var="status" noSelectionLabel="Select..."
               label="#{status.description}"/>
               <s:convertEntity />
               </h:selectOneMenu>
               </s:decorate>
              


              I spent the better part of a day trying to figure this out. The solution is not immediately obvious, and the error message was completely unhelpful to try and diagnose the problem.

              IMHO, this type of example should be part of the seam 101 examples. In every web app there is always a controlled vocabulary list where the user needs to pick a value from a list.

              Thanks for reading and replying to my post. I hope this reply helps someone in the future.

              Cheers!

              • 4. Re: Simple selectOneMenu Example/seamgen
                pmuir

                I just tested putting (with CVS) the s:convertEntity before the s:selectItems (this is the change you show, not before/after h:selectOneMenu) and it works correctly. But yes, s:convertEntity certainly needs to be inside h:selectOneMenu.

                Ignore the wiki page - it's out of date.

                • 5. Re: Simple selectOneMenu Example/seamgen
                  griffitm

                  Pete,

                  Thanks for the reply. Something really strange is going on. The best way to describe what is happening is I have several of these drop down lists, one for status, one for priority, etc. I can go in and make an unrelated change to the xhtml fragment, compile and deploy it and the error below fires on one of the list boxes. I go back to the xhtml, re-edit the selectOneMenu with the exact same information, deploy it and the problem moves to the next list box. Its like I have the wrong version of a serialized object or something. I stop/start JBoss, but the problem remains.

                  Any ideas?

                  Cheers!
                  MG

                  • 6. Re: Simple selectOneMenu Example/seamgen
                    pmuir

                    Which Seam version? There were some deproxying problems at some point I think (fixed in 2.0.0.CR1). My advice is to grab the latest CR, give it a go and come back if you are still having problems.

                    • 7. Re: Simple selectOneMenu Example/seamgen
                      griffitm

                      Pete,

                      Thanks for the reply. I am using 2.0.0.BETA1 w/JBoss 4.2.1.GA. I'll download the latest. I assume I can just overwrite my project/lib directory with the libs in the latest distro. Do I need to do anything else (other than a clean build?)

                      Cheers!
                      MG

                      • 8. Re: Simple selectOneMenu Example/seamgen
                        pmuir

                        Check also the migration guide.

                        • 9. Re: Simple selectOneMenu Example/seamgen
                          griffitm

                          Upgrading to 2.0.0.CR1 fixed the problem. Thanks!