title: JSF h:selectonemenu convertor Validation error value is not valid
body: <p>I know this has been discussed a lot, and I also tried most of resolution, but I still got this error:</p>
  
  <pre><code>    sourceId=comboNewTaskParent[severity=(ERROR 2), summary=(comboNewTaskParent: Validation Error: Value is not valid), detail=(comboNewTaskParent: Validation Error: Value is not valid)]
  </code></pre>
  
  <p>Here is the code for HTML:</p>
  
  <pre><code>    &lt;h:outputLabel value="Parent task" for="comboNewTaskParent" /&gt;
                              &lt;div class="formRight"&gt;
                                  &lt;h:selectOneMenu id="comboNewTaskParent" value="#{taskController.parentTask}" converter="#{taskConverter}"
                                      &lt;f:selectItems value="#{comboTaskByProject}" var="task" itemValue="#{task}" itemLabel="#{task.taskName}" /&gt;
                                  &lt;/h:selectOneMenu&gt;
                              &lt;/div&gt;
  </code></pre>
  
  <p>Here is the code of my entity bean:</p>
  
  <pre><code>    package com.projectportal.entity;
  
  import java.io.Serializable;
  import javax.persistence.*;
  import java.util.Date;
  import java.util.List;
  
  
  /**
   * The persistent class for the Task database table.
   * 
   */
  @Entity
  @Table(name="Task")
  public class Task implements Serializable {
  private static final long serialVersionUID = 1L;
  
  @Id
  @Column(unique=true, nullable=false, length=36)
  private String taskId;
  
  @Column(length=1000)
  private String taskDesc;
  
  @Column(nullable=false)
  private int taskDurationHour;
  
  @Temporal(TemporalType.TIMESTAMP)
  @Column(nullable=false)
  private Date taskEstimated;
  
  @Column(nullable=false, length=200)
  private String taskName;
  
  @Column(nullable=false)
  private float taskPercentComplete;
  
  @Temporal(TemporalType.TIMESTAMP)
  @Column(nullable=false)
  private Date taskStartDate;
  
  //bi-directional many-to-one association to Priority
  @ManyToOne
  @JoinColumn(name="priorityId", nullable=false)
  private Priority priority;
  
  //bi-directional many-to-one association to Project
  @ManyToOne
  @JoinColumn(name="projectId")
  private Project project;
  
  //bi-directional many-to-one association to Status
  @ManyToOne
  @JoinColumn(name="statusId", nullable=false)
  private Status status;
  
  //bi-directional many-to-one association to Task
  @ManyToOne
  @JoinColumn(name="parentTaskId")
  private Task parentTask;
  
  //bi-directional many-to-one association to Task
  @OneToMany(mappedBy="parentTask")
  private List&lt;Task&gt; childTasks;
  
  //bi-directional many-to-one association to Task
  @ManyToOne
  @JoinColumn(name="preTaskId")
  private Task preTask;
  
  //bi-directional many-to-one association to Task
  @OneToMany(mappedBy="preTask")
  private List&lt;Task&gt; dependentTasks;
  
  //bi-directional many-to-one association to UserXTask
  @OneToMany(mappedBy="task")
  private List&lt;UserXTask&gt; userXtasks;
  
  public Task() {
  }
  
  public String getTaskId() {
      return this.taskId;
  }
  
  public void setTaskId(String taskId) {
      this.taskId = taskId;
  }
  
  public String getTaskDesc() {
      return this.taskDesc;
  }
  
  public void setTaskDesc(String taskDesc) {
      this.taskDesc = taskDesc;
  }
  
  public int getTaskDurationHour() {
      return this.taskDurationHour;
  }
  
  public void setTaskDurationHour(int taskDurationHour) {
      this.taskDurationHour = taskDurationHour;
  }
  
  public Date getTaskEstimated() {
      return this.taskEstimated;
  }
  
  public void setTaskEstimated(Date taskEstimated) {
      this.taskEstimated = taskEstimated;
  }
  
  public String getTaskName() {
      return this.taskName;
  }
  
  public void setTaskName(String taskName) {
      this.taskName = taskName;
  }
  
  public float getTaskPercentComplete() {
      return this.taskPercentComplete;
  }
  
  public void setTaskPercentComplete(float taskPercentComplete) {
      this.taskPercentComplete = taskPercentComplete;
  }
  
  public Date getTaskStartDate() {
      return this.taskStartDate;
  }
  
  public void setTaskStartDate(Date taskStartDate) {
      this.taskStartDate = taskStartDate;
  }
  
  public Priority getPriority() {
      return this.priority;
  }
  
  public void setPriority(Priority priority) {
      this.priority = priority;
  }
  
  public Project getProject() {
      return this.project;
  }
  
  public void setProject(Project project) {
      this.project = project;
  }
  
  public Status getStatus() {
      return this.status;
  }
  
  public void setStatus(Status status) {
      this.status = status;
  }
  
  public Task getParentTask() {
      return this.parentTask;
  }
  
  public void setParentTask(Task parentTask) {
      this.parentTask = parentTask;
  }
  
  public List&lt;Task&gt; getChildTasks() {
      return this.childTasks;
  }
  
  public void setChildTasks(List&lt;Task&gt; childTasks) {
      this.childTasks = childTasks;
  }
  
  public Task getPreTask() {
      return this.preTask;
  }
  
  public void setPreTask(Task preTask) {
      this.preTask = preTask;
  }
  
  public List&lt;Task&gt; getDependentTasks() {
      return this.dependentTasks;
  }
  
  public void setDependentTasks(List&lt;Task&gt; dependentTasks) {
      this.dependentTasks = dependentTasks;
  }
  
  public List&lt;UserXTask&gt; getUserXtasks() {
      return this.userXtasks;
  }
  
  public void setUserXtasks(List&lt;UserXTask&gt; userXtasks) {
      this.userXtasks = userXtasks;
  }
  
  }
  </code></pre>
  
  <p>The controller:</p>
  
  <pre><code>    public @Model class TaskController {
  
  @Inject private EntityManager em;
  @Inject Identity identity;
  @Inject Logger log;
  @Inject Event&lt;Task&gt; taskEventSrc;
  
  @Named
  @Produces
  private List&lt;Task&gt; requestTaskList;
  
  private Task parentTask;
  
  private Task newTask;
  
  @Produces
  @Named
  public Task getNewTask(){
      return this.newTask;
  }
  /**
   * 
   */
  public TaskController() {
      // TODO Auto-generated constructor stub
  }
  
  @PostConstruct
  public void loadSelfTasks(){
  
      // Init
      newTask = new Task();
  
      // Get user from DB.
      User user = em.find(User.class, identity.getUser().getId());
      requestTaskList = new ArrayList&lt;Task&gt;();
  
      // Loop user's tasks.
      for(UserXTask userTask : user.getUserXtasks()){
          requestTaskList.add(userTask.getTask());
      }
  
      log.info("Tasks for user: " + user.getFirstname() + " loaded.");
  }
  
  /**
   * Create task.
   * @throws Exception
   */
  public void createTask() throws Exception{
      log.info("Persistencing task: " + newTask.getParentTask().getTaskId());
      em.persist(newTask);
      taskEventSrc.fire(newTask);
  
      newTask = new Task();
  }
  /**
   * @return the parentTask
   */
  public Task getParentTask() {
      return parentTask;
  }
  /**
   * @param parentTask the parentTask to set
   */
  public void setParentTask(Task parentTask) {
      this.parentTask = parentTask;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And of course the converter:</p>
  
  <pre><code>    @Named
  /**
   * @author lastcow
   *
   */
  </code></pre>
  
  <p>public class TaskConverter implements Converter {</p>
  
  <pre><code>@Inject EntityManager em;
  @Inject Logger log;
  
  /* (non-Javadoc)
   * @see javax.faces.convert.Converter#getAsObject(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.String)
   */
  @Override
  public Object getAsObject(FacesContext context, UIComponent component, String value)     {
      log.info("=========== Convert to Object " + value);
      if(value.equals("0")){
          return null;
      }
      Task t =  em.find(Task.class, value);
      log.info("======== Got : " + t.getTaskName());
      return t;
  }
  
  /* (non-Javadoc)
   * @see javax.faces.convert.Converter#getAsString(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
   */
  @Override
  public String getAsString(FacesContext context, UIComponent component, Object value) {
      log.info("=========== Convert to String " + value);
      return ((Task)value).getTaskId();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>from what logged, the convert are working as it, but when I try to submit the form, always throw 'Validation Error: Value is not valid' ERROR, I have struck here for almost 2 days.</p>
  
  <p>Anyone please give some suggestions.</p>
  
  <p>BTW, I tried put equals and hashCode in Task.java, doesn't working either.
  Thanks in advance.</p>