title: How to extract data from database with SelectOneMenu in Primefaces 3.2
body: <p>I'm new in primefaces 3.2. I need to get all name of department from the database in a SelectOneMenu, but i didn't !!</p>
  
  <pre><code>&lt;h:outputText value="Département : " /&gt;  
  &lt;h:selectOneMenu value="#{departementBean.departement}" converter="#{departementConverter}"&gt;
      &lt;f:selectItem itemLabel="Select One" itemValue="" noSelectionOption="true"/&gt;
      &lt;f:selectItems var="dep" value="#{departementBean.list}" itemLabel="libelleDepartement" itemValue="#{departementBean.departement}" /&gt;
  &lt;/h:selectOneMenu&gt;
  </code></pre>
  
  <p>This is the DepartementConverter from this Tuto <a href="https://stackoverflow.com/questions/6848970/how-to-prepopulate-a-hselectonemenu-from-a-db">How to populate options of h:selectOneMenu from database?</a> </p>
  
  <pre><code>@ManagedBean(name = "departementConverter")
  @RequestScoped
  public class DepartementConverter implements Converter {
  
      @ManagedProperty(value = "#{departementService}")
      private DepartementService departementService;
  
      @Override
      public Object getAsObject(FacesContext context, UIComponent component, String value) {
  
          Long id = Long.valueOf(value);
  
          try {
              return departementService.find(String.valueOf(id));
          } catch (Exception e) {
              throw new ConverterException(new FacesMessage(String.format("Cannot convert %s to Departement", value)), e);
          }
      }
  
      @Override
      public String getAsString(FacesContext context, UIComponent component, Object value) {
          Departement departement = (Departement) value;
          return String.valueOf(departement.getIdDepartement());
      }
  
      public DepartementService getDepartementService() {
          return departementService;
      }
  
      public void setDepartementService(DepartementService departementService) {
          this.departementService = departementService;
      }
  }
  </code></pre>
  
  <p>The <strong>find</strong> method From DAOImpl is as follow :</p>
  
  <pre><code>public Object find(String id) {
      return this.getHibernateTemplate().find(id);
  }
  </code></pre>
  
  <p>But when I run the project , I have this ERROR :</p>
  
  <pre><code>    INFO: Exception when handling error trying to reset the response.
  java.lang.ClassCastException: java.lang.String
      at com.majustic.majemploi.converter.DepartementConverter.getAsString(DepartementConverter.java:43)
      at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getFormattedValue(HtmlBasicRenderer.java:519)
      at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOption(MenuRenderer.java:534)
      at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:792)
      at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:844)
      at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:298)
      at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
      at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
      at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
      at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
      at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:57)
      at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:45)
      at org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:185)
      at org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:108)
      at org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:55)
      at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
      at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
      at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
      at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
      at org.primefaces.component.accordionpanel.AccordionPanelRenderer.encodeTab(AccordionPanelRenderer.java:218)
      at org.primefaces.component.accordionpanel.AccordionPanelRenderer.encodeTabs(AccordionPanelRenderer.java:147)
      at org.primefaces.component.accordionpanel.AccordionPanelRenderer.encodeMarkup(AccordionPanelRenderer.java:91)
      at org.primefaces.component.accordionpanel.AccordionPanelRenderer.encodeEnd(AccordionPanelRenderer.java:71)
      at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
      at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
      at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
      at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:128)
      at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368)
      at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
      at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:79)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:55)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:36)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:178)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:189)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:106)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
      at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:170)
      at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:238)
      at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:168)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:170)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:473)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:120)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:909)
      at java.lang.Thread.run(Thread.java:662)
  </code></pre>
  
  <p>The error is at this ligne : </p>
  
  <blockquote>
    <p>Departement departement = (Departement) value;</p>
  </blockquote>
  
  <p>Please , I can't fix the mistake. Please any help !!</p>