I want to share with you my findings on the topic of binding data originating from different HTML inputs straight into a java.util.Date.
Let's consider an example. Your HTML view has:
- an input for the day where you expect the user to enter DD/MM/YYYY
- a drop down for selecting hours
- a drop down for selecting minutes
Your form object has a java.util.Date attribute called travelDate.
- By naming all the HTML elements after the attribute name: travelDate
- Register a CustomDateEditor in your Controller (binder.registerCustomEditor) with a comma separated list of patterns that match in order the appearance of your HTML input fields. This is the trick!!
Spring will invoke the setAsText of your CustomDateEditor by passing the user input in the form of comma separated string. For instance '07/02/2007,14,37'.
This will in turn be parsed as a date.