title: selectOneMenu with converter. java.lang.Integer cannot be cast to
body: <p>Sorry for my bad english. </p>
  
  <p>I try to show a selectOneMenu using converter but throws error: </p>
  
  <p>java.lang.Integer cannot be cast to pojos.HoraRango</p>
  
  <pre><code>java.lang.ClassCastException: java.lang.Integer cannot be cast to pojos.HoraRango
  at managedBeans.HoraRangoConverter.getAsString(HoraRangoConverter.java:46)
  at org.primefaces.util.ComponentUtils.getValueToRender(ComponentUtils.java:114)
  at org.primefaces.util.ComponentUtils.getValueToRender(ComponentUtils.java:61)
  at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeLabel(SelectOneMenuRenderer.java:202)
  at or
  </code></pre>
  
  <p>my xhtml</p>
  
  <pre><code> &lt;p:outputLabel for="console" value="Basic:" /&gt;
      &lt;p:selectOneMenu id="console" value="#{bPistasDisponibles.inicioHoraElegido}" style="width:125px" converter="HoraRangoConverter"&gt;
             &lt;f:selectItems value="#{bPistasDisponibles.inicioHora}" var="inicioHora" 
                         itemLabel="#{inicioHora.hora}" itemValue="#{inicioHora}" /&gt;
      &lt;/p:selectOneMenu&gt;
  </code></pre>
  
  <p>my converter</p>
  
  <pre><code>   public class HoraRangoConverter implements Converter{
  @Override
  public Object getAsObject(FacesContext context, UIComponent component, String value) {
      if(value != null &amp;&amp; value.trim().length() &gt; 0) {
          try {
               DaoHoraRango daohoraRango =  new DaoImplHoraRango();
               HoraRango cat= daohoraRango.verHoraRango(Integer.parseInt(value));
              return cat;
  
          } catch(NumberFormatException e) {
              throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid Cine."));
          }
      }
      else {
          return null;
      }
  }
  
  @Override
  public String getAsString(FacesContext context, UIComponent component, Object value) {
      if(value != null) {
          return String.valueOf(((HoraRango)value).getIdHoraRango());
      }
      else {
          return null;
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Thanks</p>