title: bind date to command object in Grails
body: <p>I have a date (as a string) being submitted.  I'd like to map this to a command object.  I have looked around quite a bit and found no great resource on how to do this mapping within a command object to a real date.</p>
  
  <p>If I were to do this in the controller itself I could just do the following, however this doesn't allow me to easily map into my command object.</p>
  
  <pre><code>def endDate = params.date('endDate', 'MM/dd/yyyy')
  </code></pre>
  
  <p>For my command object, the closest I've been able to get is to override the getter and setter for the date object.  Both need to be overridden or else the setter is not used.  This is what I first tried (set the String to Date, but get the Date).  So this doesn't use the setter:</p>
  
  <pre><code>@grails.validation.Validateable
  class TaskCreateCommand {
  
      Date startDate
  
  
      public void setStartDate(String dateStr){
          this.start = Date.parse('MM/dd/yyyy', dateStr)
      }
  
  }
  </code></pre>
  
  <p>This doesn't give any runtime problems, but is useless because I can't pull out the actual Date object.</p>
  
  <pre><code>@grails.validation.Validateable
  class TaskCreateCommand {
  
      Date startDate
  
  
      public void setStartDate(String dateStr){
          this.start = Date.parse('MM/dd/yyyy', dateStr)
      }
  
      public String getStartDate(){
          return start.toString()
      }
  }
  </code></pre>