2 Replies Latest reply on Jul 27, 2009 4:43 PM by Manish Prajapati

    SelectItems With the Enum Values

    Manish Prajapati Newbie
      Hi All,

      I have a problem in population drop-down for enum values.

      Facelets Code:

      <h:selectOneMenu id="docCategory"  value="defaultCategory" >
      <f:selectItem itemValue="" itemLabel="Please Select" />
      <s:selectItems value="#{documentCategory}" var="category" label="#{category}"/>
      <s:convertEnum/>
      </h:selectOneMenu>

      Backing Bean:


      @Name("test")
      @Scope(ScopeType.SESSION)
      @Synchronized(timeout=100000)
      public class Test implements Serializable{
              
                private SupportingDocumentCategory defaultCategory=SupportingDocumentCategory.BANK_STATEMENT;
                private SupportingDocumentCategory[] documentCategory;
                
                @Factory(value="documentCategory")
                public SupportingDocumentCategory[] getDocumentCategory() {
                     return SupportingDocumentCategory.values();
                }
                
                public SupportingDocumentCategory getDefaultCategory() {
                     return defaultCategory;
                }

                public void setDefaultCategory(SupportingDocumentCategory defaultCategory) {
                     this.defaultCategory = defaultCategory;
                }

                public void setDocumentCategory(SupportingDocumentCategory[] documentCategory) {
                     this.documentCategory = documentCategory;
                }

                
      }

      I am getting following error while rendering the page having that selectItem:

      javax.faces.convert.ConverterException: Cannot get items
           at org.jboss.seam.ui.converter.EnumConverter.getAsObject(EnumConverter.java:33)
           at com.sun.facelets.tag.jsf.ConvertHandler.apply(ConvertHandler.java:121)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:64)
           at com.sun.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:131)
           at com.sun.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:337)
           at com.sun.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:307)
           at com.sun.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:68)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
           at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
           at com.sun.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:64)
           at com.sun.facelets.tag.ui.DecorateHandler.apply(DecorateHandler.java:116)
           at com.sun.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:337)
           at com.sun.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:307)
           at com.sun.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:68)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:119)
           at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
           at com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)
           at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:248)
           at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:294)
           at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:273)
           at com.sun.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:140)
           at com.sun.facelets.tag.ui.DecorateHandler.apply(DecorateHandler.java:105)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
           at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
           at com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)
           at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:248)
           at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:294)
           at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:273)
           at com.sun.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:140)
           at com.sun.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:113)
           at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
           at com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)
           at com.sun.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:95)
           at com.sun.facelets.FaceletViewHandler.buildView(FaceletViewHandler.java:524)
           at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:567)
           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 com.test.seam.infrastructure.BaseUrlFilter.doFilter(BaseUrlFilter.java:30)
           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:390)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
           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.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: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(Thread.java:619)

      Please, help me to resolve this problem.

      My Actual requirement is, assume i have one Enum Color and i want to populate drow-down using Color Enum.

      Kindly, guide me how i can acomplish my goal.

      Thanks a lot in advance.

      Regards,
      Manish