8 Replies Latest reply on Sep 6, 2007 1:36 PM by Todd Smart

    Enum in Seam

    carlos inigo Newbie

      I have this factory to show the enum values in my seam application:

      @Factory("tiposPoder")
       public TipoPoder[] getTipoPoder() {
       return TipoPoder.values();
       }


      This is the code of my enum:
      public enum TipoPoder implements Serializable {
      
       MANCOMUNADO("M")
       , SOLIDARIO("S");
       private String value;
       private TipoPoder(String value){
       this.value = value;
       }
       public String getValue(){
       return value;
       }
       public static TipoPoder fromValue(String s){
       for (TipoPoder obj : TipoPoder.values())
       {
       if (obj.getValue().equals(s))
       return obj;
       }
       return null;
       }
      }


      Then in my xhtml page I refer to this using the following code:
      <s:decorate template="layout/display.xhtml">
       <ui:define name="label">Tipo</ui:define>
       <h:selectOneMenu value="#{apoderadoList.apoderado.tipo}">
       <s:selectItems value="#{tiposPoder}" var="tiposPoder" label="#{tiposPoder.value}" />
       <s:convertEnum/>
       </h:selectOneMenu>
       </s:decorate>
      


      I recived the following exception in my application:
      javax.faces.el.EvaluationException: /ApoderadoList.xhtml @75,62 rendered="#{empty apoderadoList.resultList}": Exception getting value of property resultList of base of type : action.SeamApplication1.model.ApoderadoList_$$_javassist_144
      
      
      Caused by: java.lang.IllegalArgumentException: Unknown name value for enum class action.SeamApplication1.action.enums.TipoPoder: S
      
      


      Can you help me?

        • 1. Re: Enum in Seam
          Pete Muir Master

          Post the whole stack trace.

          • 2. Re: Enum in Seam
            carlos inigo Newbie

            This is the stack trace:

            09:18:33,824 INFO [STDOUT] Hibernate: select apoderado0_.apoderadoid as apoderad1_137_, apoderado0_.empresaid as empresaid137_, apoderado0_.nombre as nombre137_, apoderado0_.tipo as tipo137_, apoderado0_.gestoraid as gestoraid137_, apoderado0_.nif as nif137_, apoderado0_.poder as poder137_, apoderado0_.ambito as ambito137_, apoderado0_.registro as registro137_, apoderado0_.alta as alta137_, apoderado0_.vivo as vivo137_, apoderado0_.baja as baja137_, apoderado0_.ficherofirma as fichero12_137_ from fondval.dbo.apoderado apoderado0_ where apoderado0_.vivo=?
            09:18:33,883 ERROR [STDERR] 29-jun-2007 9:18:33 com.sun.facelets.FaceletViewHandler handleRenderException
            GRAVE: Error Rendering View[/ApoderadoList.xhtml]
            javax.faces.el.EvaluationException: /ApoderadoList.xhtml @75,62 rendered="#{empty apoderadoList.resultList}": Exception getting value of property resultList of base of type : action.SeamApplication1.model.ApoderadoList_$$_javassist_84
             at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:60)
             at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:1075)
             at org.ajax4jsf.framework.renderer.RendererBase.renderChild(RendererBase.java:276)
             at org.ajax4jsf.framework.renderer.RendererBase.renderChildren(RendererBase.java:262)
             at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:189)
             at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:184)
             at org.ajax4jsf.framework.renderer.RendererBase.encodeChildren(RendererBase.java:121)
             at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:524)
             at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:244)
             at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:249)
             at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:249)
             at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:573)
             at org.ajax4jsf.framework.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
             at org.ajax4jsf.framework.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:233)
             at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:384)
             at javax.faces.webapp.FacesServlet.service(FacesServlet.java:138)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
             at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:63)
             at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:60)
             at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
             at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
             at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
             at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:57)
             at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
             at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:79)
             at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:49)
             at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:84)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
             at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
             at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
             at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
             at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
             at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
             at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
             at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
             at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
             at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
             at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
             at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
             at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
             at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
             at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
             at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
             at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
             at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
             at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
             at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
             at java.lang.Thread.run(Thread.java:595)
            Caused by: javax.faces.el.EvaluationException: Bean: action.SeamApplication1.model.ApoderadoList_$$_javassist_84, property: resultList
             at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:442)
             at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:82)
             at com.sun.facelets.el.LegacyELContext$LegacyELResolver.getValue(LegacyELContext.java:141)
             at com.sun.el.parser.AstValue.getValue(AstValue.java:125)
             at com.sun.el.parser.AstEmpty.getValue(AstEmpty.java:49)
             at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:195)
             at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
             at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:56)
             ... 51 more
            Caused by: java.lang.reflect.InvocationTargetException
             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.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:438)
             ... 58 more
            Caused by: java.lang.IllegalArgumentException: Unknown name value for enum class action.SeamApplication1.action.enums.TipoPoder: S
             at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:104)
             at org.hibernate.type.CustomType.nullSafeGet(CustomType.java:105)
             at org.hibernate.type.AbstractType.hydrate(AbstractType.java:81)
             at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2031)
             at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1371)
             at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1299)
             at org.hibernate.loader.Loader.getRow(Loader.java:1197)
             at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:568)
             at org.hibernate.loader.Loader.doQuery(Loader.java:689)
             at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
             at org.hibernate.loader.Loader.doList(Loader.java:2144)
             at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
             at org.hibernate.loader.Loader.list(Loader.java:2023)
             at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:393)
             at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
             at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
             at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
             at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
             at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:64)
             at org.jboss.seam.framework.EntityQuery.getResultList(EntityQuery.java:42)
             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:20)
             at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57)
             at org.jboss.seam.interceptors.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:34)
             at org.jboss.seam.intercept.SeamInvocati
            09:18:33,896 ERROR [STDERR] onContext.proceed(SeamInvocationContext.java:69)
             at org.jboss.seam.interceptors.TransactionInterceptor$1.work(TransactionInterceptor.java:32)
             at org.jboss.seam.util.Work.workInTransaction(Work.java:37)
             at org.jboss.seam.interceptors.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:27)
             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
             at org.jboss.seam.interceptors.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:27)
             at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:69)
             at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:103)
             at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:151)
             at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:87)
             at action.SeamApplication1.model.ApoderadoList_$$_javassist_84.getResultList(ApoderadoList_$$_javassist_84.java)
             ... 63 more
            Caused by: java.lang.IllegalArgumentException: No enum const class action.SeamApplication1.action.enums.TipoPoder.S
             at java.lang.Enum.valueOf(Enum.java:192)
             at org.hibernate.type.EnumType.nullSafeGet(EnumType.java:101)
             ... 101 more
            


            • 3. Re: Enum in Seam
              Pete Muir Master

              Looks like you've got bad data in your database - hibernate is trying to convert get the enum TipoPoder.S which doesn't exist in your code.

              • 4. Re: Enum in Seam
                carlos inigo Newbie

                In my database I have 'S' and 'M' data. What I want to display is MANCOMUNDO for 'M' and SOLIDARIO for 'S' in a h:selectOneMenu.
                Is there another way to do this?
                It still doesn't work.
                Thanks for all.

                • 5. Re: Enum in Seam
                  Pete Muir Master

                   

                  public enum TipoPoder {
                  
                   M("MANCOMUNADO"), S("SOLIDARIO");
                  
                   private String label;
                   TipoPoder(String label){
                   this.label = label;
                   }
                   public String getLabel(){
                   return label;
                   }
                  }


                  @Enumerated(STRING) TipoPoder tipoPoder;


                  • 6. Re: Enum in Seam
                    jfrankman Novice

                    Pete,

                    Thanks for the example. What if a number is stored in the database instead of a string? When I try to do this:


                    public enum TypePayment
                    {
                    1("ANNUAL"),
                    2("SEMIANNUAL");
                    


                    I get a compile error. Is there a way I could still use and enumeration when the data stored in the database is numeric?


                    • 7. Re: Enum in Seam
                      Pete Muir Master

                      Sorry, no idea. Try asking on the hibernate forums

                      • 8. Re: Enum in Seam
                        Todd Smart Newbie

                        Hi - just in-case you didn't find a solution to this...and are willing to just use the ordinals from the enum...you should be able to use:

                         public enum Status implements Serializable {
                         ACTIVE,
                         CANCELLED,
                         SIGNED;
                         }
                        


                        Then:

                         @Column(name = "doc_status_cd")
                         @Enumerated(EnumType.ORDINAL)
                         public Status getStatus() {
                         return status;
                         }
                        


                        Just make sure that your db field (doc_status_cd) in the above example is a numeric type of some sort.


                        Regards,

                        Todd