title: JSF Converter not converting between String and class
body: <p>Changing the selectOneMenu to this. Solved the issue for me. Now my problem is that the page seems to be called several times ending up messing up the selection.</p>
  
  <p>But switching the value to #{st} instead of serieType would solved the issue with failing to assign the string to the class. Now it's correctly handled as a class. This makes no sense whatsoever to me since I have another selectonemenu where I use the player which is another bean. and set the value to #{player} but anyway this works. </p>
  
  <p>Now I just need to figure out why my selection is altered when calling the page again.</p>
  
  <pre><code>&lt;p:selectOneMenu value="#{st}" 
                      converter="serieTypeConverter" id="serieTypeList"&gt;
                      &lt;f:selectItem itemLabel="---" noSelectionOption="true" /&gt;
                  &lt;f:selectItems value="#{serviceSerieType.serieTypes}"
                       var="st"
                       itemValue="#{st}"
                       itemLabel="#{st.serie_type}"
                       itemLabelEscaped="true"/&gt;
                  &lt;/p:selectOneMenu&gt;
  </code></pre>
  
  <p>Additional information</p>
  
  <p>Below suggested solution will not work. It actually end up trying to assign a SerieType class to the serieType.selectedValue eventhough it's prototype is this</p>
  
  <pre><code>private String selectedValue;
  
  &lt;p:selectOneMenu value="#{serieType.selectedValue}" 
                      converter="serieTypeConverter" id="serieTypeList"&gt;
                  &lt;f:selectItems value="#{serviceSerieType.serieTypes}"
                       var="st"
                       itemValue="#{st}"
                       itemLabel="#{st.serie_type}"
                       itemLabelEscaped="true"/&gt;
                  &lt;/p:selectOneMenu&gt;
  </code></pre>
  
  <p>Somewhere in the form I get below error. I can figure out where it goes wrong. I can't see any apparent reason for it since I am using an identical converter for another class with just the class name changed. There is a service that return a SerieType class either by a long ID och string ID. </p>
  
  <pre><code>SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/BowlingFacelets] threw exception [Cannot convert Match of type class java.lang.String to class com.jk.hcp.SerieType] with root cause
  javax.el.ELException: Cannot convert Match of type class java.lang.String to class com.jk.hcp.SerieType
      at org.apache.el.lang.ELSupport.coerceToType(ELSupport.java:420)
  </code></pre>
  
  <p>These are the only two places in the xhtml it's used</p>
  
  <pre><code>&lt;h:selectOneListbox size="1" value="#{serieType}" 
                      converter="serieTypeConverter" id="serieTypeList"&gt;
                  &lt;f:selectItems value="#{serviceSerieType.serieTypes}"
                       var="st"
                       itemValue="#{st}"
                       itemLabel="#{st.serie_type}"
                       itemLabelEscaped="true"/&gt;
                  &lt;/h:selectOneListbox&gt;
  
  
  &lt;c:forEach var="list" items="#{serviceSeries.getClubAverages(club.name, serieType, calendarBean)}"&gt;
  </code></pre>
  
  <p>In the ServiceSerieType</p>
  
  <pre><code>public List&lt;SerieType&gt; getSerieTypes() {
  public SerieType getSerieTypeByID(long id) {
  public SerieType getSerieTypeByStringID(String id) {
  
  
  @FacesConverter(value = "serieTypeConverter")
  public class SerieTypeConverter implements Converter {
  
      @Override
      public Object getAsObject(FacesContext context, UIComponent component, String value) {
          if (value == null) {
              return null;
          }
  
          long idValue;
          try {
              idValue = Long.parseLong(value);
          }
          catch (NumberFormatException ex)
          {
              return null;
          }
  
  
          ServiceSerieType serviceSerieType = 
                  context.getApplication().evaluateExpressionGet(context, "#{serviceSerieType}", ServiceSerieType.class);
  
          SerieType serieType = serviceSerieType.getSerieTypeByID(idValue);
  
          return serieType;
  
      }
  
      @Override
      public String getAsString(FacesContext context, 
                                    UIComponent component, Object value) {
          if (value == null || value.equals("")) {
              return "";
          } else {
              return String.valueOf(((SerieType)value).getStringID()); 
          }
      }
  
  }
  
  @ManagedBean
  public class SerieType implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
      private String serie_type;
      private String serie_type_info;
  
  
      public String getSerie_type_info() {
          return serie_type_info;
      }
  
      public void setSerie_type_info(String serie_type_info) {
          this.serie_type_info = serie_type_info;
      }
  
      private static final long serialVersionUID = 1L;
  
      public SerieType() {
          super();
      }   
  
      public Long getId() {
          return this.id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }   
      public String getSerie_type() {
          return this.serie_type;
      }
  
      public void setSerie_type(String serie_type) {
          this.serie_type = serie_type;
      }
  
      public String getStringID() {
          if (id == null)
              return "0";
          return id.toString();
      }
  
      public void setStringID(String value) {
          if (value == null)
              return;
  
          try {
              this.id = Long.parseLong(value);
          }
          catch (NumberFormatException ex) {
  
          }
      }
  
      @Override
      public boolean equals(Object other) {
          return (id != null &amp;&amp; other != null &amp;&amp; getClass() == other.getClass())
               ? id.equals(((SerieType) other).getId())
               : (other == this);
      }
  
      @Override
      public int hashCode() {
          return (id != null) 
               ? (getClass().hashCode() + id.hashCode()) 
               : super.hashCode();
      }
      /*
      @Override
      public String toString() {
          return this.serie_type + " " + this.serie_type_info;
      }
      */
  
  }
  </code></pre>