title: How to @Valid a Date only if users insert it (Spring MVC + Hibernate)
body: <p>I have this POJO, used as <code>modelAttribute</code> in a form, that allow users to search record on the DB:</p>
  
  <pre><code>public class FatherSearch extends Father{
      ...
      @Past   
      @DateTimeFormat(pattern = "dd/MM/yyyy")
      private Date dataDiNascita; 
      ...
  }
  </code></pre>
  
  <p>I have to check if the date inserted by the users is a <code>@Past</code> date; I should check the date just if users insert it.</p>
  
  <p>The problem is that since dataDiNascita is a <code>Date</code> it can't be null and when users submit the form without filling the date field, they get the error <code>typeMismatch</code>.</p>
  
  <p>Here is the controller where I get the error:</p>
  
  <pre><code>@RequestMapping("/admin/fatherSearchSent")
  public String fatherSearchSent(..., @Valid FatherSearch fatherSearch,...){
  }
  </code></pre>
  
  <p>I have to allow users to decide whether insert a date in the search form or not, so I need a way to handle the case in which users don't insert any date.</p>
  
  <p>Thank you</p>