I would like to have HTML <input type="date">
component with date picker and so on.
I cant make it work with Wicket. I need to change the model value on onChange() event without Submit Form and I need to show the initial value in input field of the java.util.Date object from my Model, which is not working too.
My code java:
IModel<Date> model = new Model<Date>() {
private Date date = new Date();
public Date getObject() {
return date;
}
public void setObject(Date object) {
this.date = object;
}
};
DateTextField dateTo = new DateTextField("date", model);
dateTo.add(new OnChangeAjaxBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
System.out.println(model.getObject()); <-- it is still null
}
});
add(dateTo);
HTML markup:
<input type="date" wicket:id="date" />
As you can see, date is initialize as new Date(), but in <input type="date">
I can see only dd.mm.yyyy and same as setObject() method. The Date object param is always null after change.
What am I doing wrong? Thanks for any answer.
The HTML date input fields send the data back to the server in the format
2012-12-30
. So you need to configure the WicketDateTextField
to parse that format:See also: https://stackoverflow.com/a/9519493/2511197