title: JSF 2 - Bean Validation: validation failed -> empty values are replaced with last valid values from managed bean
body: <p><br>
  I do not understand the behaviour of JSF2 during valdation. Hope someone can help me.  </p>
  
  <p>I have a form where the fields are validated after (ajax) submit - ok<br>
  If the validation failed a error message is shown - ok</p>
  
  <p>For my example when I enter a valid <em>birthday</em> and the field <em>name</em> is empty an errormessage for <em>name</em> is shown after submit.<br>
  Now when I enter a valid <em>name</em> and delete the input from the <em>birthday</em> field an errormessage is show for <em>birthday</em> (that's ok) but now the old 'valid' <em>birthday</em> stands also in the input field!?!  </p>
  
  <p>How can I avoid this behaviour?
  When I submit an empty field I want to see an errormessage and an empty field...</p>
  
  <p>Here's my sample code:  </p>
  
  <p>I use a ManagedBean (<em>TestBean</em>) that contains an EntityBean (<em>Contact</em>). The <em>Contact</em> contains validations per annoations.</p>
  
  <pre><code>public class Contact implements Serializable {
      @NotNull 
      @Temporal(TemporalType.DATE)
      private Date birthday;
  
      @NotNull 
      @Size(min=3, max=15)
      private String name;
  
      //...
  }
  </code></pre>
  
  <p>My <em>ManagedBean</em>:  </p>
  
  <pre><code>@ManagedBean
  @ViewScoped
  public class TestBean implements Serializable {
      private Contact contact;
  
      @PostConstruct
      void init() {
          System.out.println("init...");
          contact = new Contact(); 
      }
  
      public void newContact(ActionEvent ae) {
          System.out.println("newContact...");
          contact = new Contact();
      }
  
      public void save() {
          System.out.println("save...");
          //TODO do something with contact...
      }
  
      public Contact getContact() { return contact; }
  
      public void setContact(Contact contact) {this.contact = contact;}
  }
  </code></pre>
  
  <p>An here my JSF page:  </p>
  
  <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&gt;     
          &lt;h:panelGrid columns="3"&gt;   
  
          &lt;h:outputText value="Birthday: " /&gt;  
          &lt;h:inputText id="birthday" value="#{testBean.contact.birthday}"&gt;
              &lt;f:convertDateTime/&gt;
          &lt;/h:inputText&gt;  
          &lt;h:message for="birthday" /&gt;  
  
          &lt;h:outputText value="Name: " /&gt;  
          &lt;h:inputText id="name" value="#{testBean.contact.name}"/&gt;
          &lt;h:message for="name" /&gt;
  
          &lt;/h:panelGrid&gt;  
  
          &lt;h:commandButton value="submit" action="#{testBean.save}"&gt; 
              &lt;f:ajax execute="@form" render="@form"/&gt;
          &lt;/h:commandButton&gt; 
  
          &lt;h:commandButton value="newContact" actionListener="#{testBean.newContact}"
                           immediate="true"&gt; 
              &lt;f:ajax render="@form"/&gt;
          &lt;/h:commandButton&gt; 
  
      &lt;/h:form&gt;
  &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>at last a snippet from web.xml  </p>
  
  <pre><code>&lt;context-param&gt;
      &lt;param-name&gt;javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL&lt;/param-name&gt;
      &lt;param-value&gt;true&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;context-param&gt;
      &lt;param-name&gt;javax.faces.VALIDATE_EMPTY_FIELDS&lt;/param-name&gt;
      &lt;param-value&gt;true&lt;/param-value&gt;
  &lt;/context-param&gt;
  </code></pre>
  
  <p>Thanks for some tips</p>