I'm using the Struts2-jQuery Datepicker
with the Timepicker
Addon.
Assuming that a java.util.Date
object is returned form an Action
getMyDate()
getter method:
<sj:datepicker displayFormat="dd/mm/yy"
timepickerFormat="HH:mm"
timepicker="true"
name="myDate" />
This always results in the date being populated correctly, but the timepicker
is always 00:00
.
Ok, I've found the time to expand the solution I've figured out on 18 december and briefly mentioned in the comments.
The Problem
The
<sj:datepicker timepicker="true">
tag correctly parses a Date object, but not its String representation. This is reported in Issue 1057, with status accepted but still not fixed.This works:
This does NOT work:
When not using a Converter, you need to send the format of the date-time to a
String
variable, instead than to aDate
one:If you need a Date (you probably do), you can use a String Getter and Setter, that will handle the parsing and the formatting between Date and String:
But both this methods, due to the bug linked above, won't work. The solution is so easy that made me laugh in my last comment to the question:
The Solution
Use a String setter, and a Date getter, then it will work perfectly:
(or write a Converter).
Side note:
timepickerFormat="HH:mm"
is not needed becauseHH:mm
(24 hours format) is already the default format. You need to change it only if you want the 12 hours display format.