title: Validation Error: Value is not valid
body: <p>I have a problem with a p:selectOneMenu, no matter what I do I cannot get JSF to call the setter on the JPA entity. JSF validation fails with this message:</p>
  
  <blockquote>
    <p>form:location: Validation Error: Value is not valid</p>
  </blockquote>
  
  <p>I have this working on several other class of the same type (ie, join table classes) but cannot for the life of me get this one working.</p>
  
  <p>If anyone can throw some troubleshooting/debugging tips for this sort of problem it would be greatly appreciated.</p>
  
  <p>Using log statements I have verified the following:</p>
  
  <ol>
  <li>The <code>Conveter</code> is returning correct, non <code>null</code> values.</li>
  <li>I have no Bean Validation in my JPA entities.</li>
  <li>The setter <code>setLocation(Location location)</code> is never called.</li>
  </ol>
  
  <p>This is the simplest example I can do and it simply will not work:</p>
  
  <pre><code>&lt;h:body&gt;
      &lt;h:form id="form"&gt;
          &lt;p:messages id="messages" autoUpdate="true" /&gt;
          &lt;p:selectOneMenu id="location" value="#{locationStockList.selected.location}" converter="locationConverter"&gt;
              &lt;p:ajax event="change" update=":form:lblLocation"/&gt;
              &lt;f:selectItems value="#{locationStockList.locationSelection}"/&gt;
          &lt;/p:selectOneMenu&gt;
      &lt;/h:form&gt;
  &lt;/h:body&gt;
  </code></pre>
  
  <p>Converter:</p>
  
  <pre><code>@FacesConverter(forClass=Location.class, value="locationConverter")
  public class LocationConverter implements Converter, Serializable {
      private static final Logger logger = Logger.getLogger(LocationConverter.class.getName());
  
      @Override
      public Object getAsObject(FacesContext context, UIComponent component, String value) {
          if (value.isEmpty())
              return null;
          try {
              Long id = Long.parseLong(value);
              Location location = ((LocationManagedBean) context.getApplication().getELResolver().getValue(context.getELContext(), null, "location")).find(id);
              logger.log(Level.SEVERE, "Converted {0} to {1}" , new Object[] {value, location});
              return location;
          } catch (NumberFormatException e) {
              return new Location();
          }
      }
  
      @Override
      public String getAsString(FacesContext context, UIComponent component, Object value) {
          if (value == null || value.toString().isEmpty() || !(value instanceof Location))
              return "";
          return String.valueOf(((Location) value).getId());
      }    
  }
  </code></pre>
  
  <p>Console output:</p>
  
  <pre><code>// Getter method
  INFO: Current value=ejb.locations.Location[id=null, name=null, latitude=0.0, longitude=0.0] 
  // Session Bean
  INFO: Finding ejb.locations.Location with id=3 
  // Session Bean
  INFO: ### Returning : ejb.locations.Location[id=3, name=mdmd, latitude=4.5, longitude=2.3] 
  // Converter
  SEVERE: Converted 3 to ejb.locations.Location[id=3, name=mdmd, latitude=4.5, longitude=2.3] 
  // Getter method -&gt; Where did my selected Location go ??
  INFO: Current value=ejb.locations.Location[id=null, name=null, latitude=0.0, longitude=0.0] 
  </code></pre>