Concrete example would be implementation of a Convertor/PropertyEditor for (2011, 11, 24, 8, 10, AM) request parameters to Date object ?
Let say that my UI uses a widget that uses 6 html form fields for calendar (2011, 11, 24, 8, 10, AM) - which is very inconvenient ..
Ideal solution would be if the parameter was only one - "yyyy:MM:dd:hh:mm:aa", @DateTimeFormat annotation was on the field and the WebDataBinder has been set with the DefaultConversionService + joda-time is on the classpath.
But I have to keep look and feel and use that widget. Also doing that conversion in handler method complicates validation a lot. Any idea how to do that without bothering in handler method ?
If you create a custom wrapper object that have fields for each of the input parameters, having public ... handlerMethod(InputDate date)
will populate it. Then, in the same class, you can have toDateTime()
which will construct a DateTime
based on the input.
You can also use a custom WebArgumentResolver
and have a custom annotation, for example @InputDate
, in your method signature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With