title: JSF Validation Error While Using Custom Converter
body: <p>I am setting up a form using JSF (I'm pretty new at this) and I am getting a <code>Validation Error: Value is not valid</code> message on one of the fields.  This field is actually a separate object (as I will show below) that has a custom converter.</p>
  
  <p>Here is what I have (with non-relevant code removed):</p>
  
  <p>I have a <code>Citation</code> class:</p>
  
  <pre><code>@ManagedBean(name="citation")
  public class Citation {
      private int id;
      private Status status;
  
      // getters and setters
  }
  </code></pre>
  
  <p>I also have a <code>Status</code> class that you see referenced in the <code>Citation</code> class:</p>
  
  <pre><code>@ManagedBean(name="status")
  public class Status {
      private int id;
      private String name;
  
      // getters and setters
  
      public List&lt;Status&gt; getAllStatuses() {
          Session session = HibernateUtil.getCurrentSession();
          session.beginTransaction();
          session.clear();
  
          Query query = session.createQuery("from Status");
          List&lt;Status&gt; statuses = query.list();
  
          try {
              session.getTransaction().commit();
          } catch (HibernateException e) {
              // TODO: handle exception
              session.getTransaction().rollback();
          }
  
          return statuses;
      }
  
      @Override
      public boolean equals(Object obj) {
          if (obj == null) return false;
          if (!(obj instanceof Status)) return false;
  
          if (this.id == ((Status)obj).getId()) {
              return true;
          } else {
              return false;
          }
      }
  
      @Override
      public int hashCode() {
          return this.name.hashCode();
      }
  }
  </code></pre>
  
  <p>Then for my form, I have:</p>
  
  <pre><code>&lt;h:selectOneMenu id="citation_status" value="#{citation.status}"&gt;
      &lt;f:selectItems value="#{status.allStatuses} var="s" itemValue="#{s.id}" itemLabel="#{s.name}" /&gt;
  &lt;/h:selectOneMenu&gt;
  &lt;h:message for="citation_status" /&gt;
  </code></pre>
  
  <p>Lastly, for my converter, I have:</p>
  
  <pre><code>@FacesConverter(forClass=Status.class)
  public class StatusConverter implements Converter {
      @Override
      public Object getAsObject(FacesContext context, UIComponent component, String value) {
          // uses Hibernate to get the Status object (using a breakpoint in Eclipse, I have verified that this works)
          // I can post this code if needed, but just trying to keep it short :)
      }
  
      @Override
      public String getAsString(FacesContext context, UIComponent component, Object value) {
          return String.valueOf(((Status) value).getId());
      }
  }
  </code></pre>
  
  <p>Now when I get to my form and submit, I get the <code>Validation Error</code> next to the Status.  I'm pretty new at this and thanks to @BalusC, I'm this far along.</p>
  
  <p>Any help is greatly appreciated.</p>