title: JSF2 h:selectOneMenu shows old value when Validation Failed
body: <p>I have a form with few input fields &amp; a select one menu.
  All fields are required="true", 
  firstName, lastName, emailAddress, password, country.</p>
  
  <p>Test Case # 1:
  1) Enter values in all input fields, leave firstName field without entering any value,<br>
     Select a country (eg: United States) and submit the form, we can see error message 
     for firstName field required.</p>
  
  <p>2) Keep the form as it is, with leaving firstName field without entering any value, 
     then select country to "select one", and submit the form. we can see error message 
     for firstName &amp; country fields, But where as in dropdown it did not show "Select One", 
     it shows United States (the previous selection).</p>
  
  <p>I have the same problem with input fields, but i solved with a converter.
  Is there a way to solve this one. I went with few posts in stackoverflow, came to know that it is a bug in mojarra.</p>
  
  <p>Here is my code...</p>
  
  <h2>userRegistration.xhtml</h2>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core" &gt;      
   &lt;h:body&gt;
      &lt;h:form id="registrationForm"&gt;     
      &lt;h:messages layout="table" infoClass="infoMsgs" errorClass="errMsgs"/&gt;
  
      &lt;table&gt;
          &lt;tr&gt;
              &lt;td&gt;First Name:&lt;/td&gt;
              &lt;td&gt;
                  &lt;h:inputText size="40" maxlength="100" 
                               required="true" 
                               styleClass="#{component.valid ? '' : 'text_error'}"
                               value="#{registrationAction.firstName}" /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Last Name:&lt;/td&gt;
              &lt;td&gt;
                  &lt;h:inputText size="40" maxlength="100" 
                               required="true" 
                               styleClass="#{component.valid ? '' : 'text_error'}"
                               value="#{registrationAction.lastName}" /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Email Address:&lt;/td&gt;
              &lt;td&gt;
                  &lt;h:inputText size="40" maxlength="100" 
                               required="true" 
                               styleClass="#{component.valid ? '' : 'text_error'}"
                               value="#{registrationAction.emailAddress}" /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Password:&lt;/td&gt;
              &lt;td&gt;
                  &lt;h:inputSecret size="20" maxlength="15" 
                               required="true" 
                               styleClass="#{component.valid ? '' : 'text_error'}"
                               value="#{registrationAction.password}" /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Country:&lt;/td&gt;
              &lt;td&gt;
                  &lt;h:selectOneMenu id="yourCountry" name="yourCountry"    
                                   value="#{shortRegistrationAction.shortRegistrationForm.selectedCountry}"
                                   required="true" 
                                   styleClass="#{component.valid ? '' : 'text_error'}"&gt;
                      &lt;f:selectItem itemValue="#{null}" itemLabel="-Select One-" /&gt;
                      &lt;f:selectItems value="#{registrationAction.countryList}" /&gt;
                  &lt;/h:selectOneMenu&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&amp;#160;&lt;/td&gt;
              &lt;td&gt;
                  &lt;h:commandButton name="RegisterButton" id="RegisterButton" 
                                   styleClass="submitbutton"
                                   value="Register"
                                   action="#{registrationAction.registerUser}" /&gt;
              &lt;/td&gt;
      &lt;/table&gt;
      &lt;/h:form&gt;
  &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <h2>RegistrationAction.java</h2>
  
  <pre><code>package com.ebiz.web.bean;
  
  import java.io.Serializable;
  import java.util.List;
  
  import javax.annotation.PostConstruct;
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.ManagedProperty;
  import javax.faces.bean.ViewScoped;
  import com.ebiz.service.ICountryService;
  import com.ebiz.service.IUserService;
  import com.ebiz.vo.UserVO;
  import org.apache.log4j.Logger;
  
  @ManagedBean(name = "registrationAction")
  @ViewScoped
  public class RegistrationAction implements Serializable {
  
      private static final long serialVersionUID = 1L;
      private static final Logger log = Logger.getLogger(RegistrationAction.class);
  
      @ManagedProperty("#{countryService}")
      private ICountryService countryService;
  
      @ManagedProperty("#{userService}")
      private IUserService userService;
  
      private String firstName;
      private String lastName;
      private String emailAddress;
      private String password;
      private String selectedCountry;
      private List&lt;String&gt; countryList;
  
      @PostConstruct
      public void init(){
          countryList = countryService.getCountryList();
      }
  
      public void registerUser() {
  
          UserVO userVO = new UserVO();
          userVO.setFirstName(firstName);
          userVO.setLastName(lastName);
          userVO.setEmailAddress(emailAddress);
          userVO.setPassword(password);
          userVO.setCountry(selectedCountry);
  
          userService.registerUser(userVO);
  
      }
  }
  </code></pre>
  
  <h2>InputTextTrimmer.java</h2>
  
  <pre><code>package com.ebiz.web.converter;
  
  import javax.faces.component.EditableValueHolder;
  import javax.faces.component.UIComponent;
  import javax.faces.context.FacesContext;
  import javax.faces.convert.Converter;
  import javax.faces.convert.FacesConverter;
  
  @FacesConverter(forClass=String.class)
  public class InputTextTrimmer implements Converter {
  
      @Override
      public Object getAsObject(FacesContext context, UIComponent component, String value) {
          //return value != null ? value.trim() : null;
           if (value == null || value.trim().isEmpty()) {
               if (component instanceof EditableValueHolder) {
                   ((EditableValueHolder) component).setSubmittedValue(null);
                   ((EditableValueHolder) component).resetValue();
               }
               return null;
           }
           return value;
      }
  
      @Override
      public String getAsString(FacesContext context, UIComponent component, Object value) {
          return (value == null) ? null : value.toString();
      }
  
  }
  </code></pre>