title: Populating a chlid jSF selectOneMenu - implicit value validation error
body: <p>As you can see in the screenshot, I am having a <strong>JSF implicit value validation error</strong> for the property "member.city".
  The purpose is to -through ajax - populate the city select One Menu after selecting a country on the previous Country Select one menu.
  This is achieved by using <strong>selectOneMenu change listener</strong> and <strong>ajax</strong> to update the component displaying list of cities. However, I get a validation error and the form is not submitted.</p>
  
  <p><img src="https://i.stack.imgur.com/IkXiR.jpg" alt="Validation error screenshot"></p>
  
  <p>I tried with Entities <strong>with and without (hascode and equals methods)</strong>, but in vain.
  I used a <strong>separated Managed Bean ViewScoped</strong> to retrive the filtered list, but in vain.
  **</p>
  
  <blockquote>
    <p>If I replace the filtered list of cities by the list that retrieves all
    cities (in the xhtml form, replace <code>&lt;f:selectItems value="#{cityBean.citiesByCountry}" /&gt;</code> by <code>&lt;f:selectItems value="#{cityBean.all}" /&gt;</code>, there's no validation error and the form successfully gets
    submitted.</p>
  </blockquote>
  
  <p>**
  Here is the code:</p>
  
  <p><strong>Form:</strong></p>
  
  <pre><code>&lt;p:outputLabel for="country" value="#{i18n.country}" /&gt;
                      &lt;p:selectOneMenu valueChangeListener="#{cityBean.selectCountry}" rendered="true" id="country" value="#{newMember.country}" converter="#{countryBean.converter}" 
                          style="width:160px;text-align:left;border:thin solid gray;"
                          required="true" requiredMessage="#{i18n.required}"&gt;                     
                          &lt;f:selectItems value="#{countryBean.all}" var="countryname" itemLabel="#{countryname.name}"/&gt;
                          &lt;p:ajax event="change" update="city" /&gt;
                      &lt;/p:selectOneMenu&gt;
                      &lt;p:message for="country" /&gt;
  
                      &lt;p:outputLabel for="city" value="#{i18n.city}" /&gt;
                      &lt;p:selectOneMenu rendered="true" id="city" value="#{newMember.city}" converter="#{cityBean.converter}" converterMessage="Conversion error!"
                          style="width:160px;text-align:left;border:thin solid gray;"
                          required="true" requiredMessage="#{i18n.required}"&gt;                                         
                          &lt;f:selectItems value="#{cityBean.citiesByCountry}" var="cityname" itemLabel="#{cityname.cityname}"/&gt;                        
                      &lt;/p:selectOneMenu&gt;
                      &lt;p:message for="city" /&gt;
  </code></pre>
  
  <p><strong>City Entity head:</strong></p>
  
  <pre><code>@XmlRootElement
  @Entity
  @Table(name = "city", schema = "public")
  @NamedQueries({
          @NamedQuery(name = "City.findAll", query = "SELECT c FROM City c"),
          @NamedQuery(name = "City.findById", query = "SELECT c FROM City c WHERE c.id = :id"),
          @NamedQuery(name = "City.findByCountry", query = "SELECT c FROM City c WHERE c.country = :country"),
          @NamedQuery(name = "City.findByCountryOrderedByName", query = "SELECT c FROM City c WHERE c.country = :country ORDER BY c.cityname ASC") })
  @NamedNativeQueries({ @NamedNativeQuery(name = "City.findCountryNativeSQL", query = "select * from city c where c.countrybeta = :country.betacode", resultClass = City.class) })
  public class City implements java.io.Serializable {
  
      private static final long serialVersionUID = 3364735938266980295L;
      private int id;
      private Integer version;
      private Country country;
      private String cityname;
      private String district;
      private int population;
      private Set&lt;Member&gt; members = new HashSet&lt;Member&gt;(0);
  
      public City() {
      }
  // ...remainder of entity code (contructors and fields..)
  </code></pre>
  
  <p><strong>The Bean:</strong></p>
  
  <pre><code>@Named
  @Stateful
  @ConversationScoped
  public class CityBean implements Serializable {
  
      private static final long serialVersionUID = 1L;
      private City city;
      private List&lt;City&gt; cityList;
  
      public City getCity() {
          return this.city;
      }
  
      private Country selectedCountry;
  
      @Inject
      private Conversation conversation;
  
      @PersistenceContext(type = PersistenceContextType.EXTENDED)
      private EntityManager entityManager;
  // remainder of code....
  
  // The List that works fine with Select one Menu
  public List&lt;City&gt; getAll() {
  
          CriteriaQuery&lt;City&gt; criteria = this.entityManager.getCriteriaBuilder()
                  .createQuery(City.class);
          return this.entityManager.createQuery(
                  criteria.select(criteria.from(City.class))).getResultList();
      }
  
      @PostConstruct
      public void init() {
          setCityList(getCitiesByCountry());
      }
  
      public List&lt;City&gt; getCityList() {
          return cityList;
      }
  
      public void setCityList(List&lt;City&gt; cityList) {
          this.cityList = cityList;
      }
  
      /**
       * The List That triggers a jsf value validation error
       * @return List of Cities by Country ordered by city name
       */
      public List&lt;City&gt; getCitiesByCountry() {
          TypedQuery&lt;City&gt; query = this.entityManager.createNamedQuery(
                  "City.findByCountryOrderedByName", City.class);
          query.setParameter("country", selectedCountry);
          return query.getResultList();
      }
  
      // The Select One Menu Listener
      public void selectCountry(ValueChangeEvent event) {
  
          if (event != null) {
              selectedCountry = (Country) event.getNewValue();
          }
          }
  
          // getters and setters....
  </code></pre>
  
  <p>ENV:
  - JSF 21
  - Hibernate
  - JBoss AS 7.1
  - PrimeFaces 3.5
  - Linux 3.5 / Firefox 18.0.2</p>