Hi,
i cant help you with the datepicker (im on 1.3) , but to have
special-formated dates in an TextField you need sth like this:
new Model() {
@Override
public Object getObject() {
Date dt = new Date(getYourDate());
SimpleDateFormat sdf = new
SimpleDateFormat("d.M.yyyy");
return sdf.format(dt);
}
@Override
public void setObject(Serializable object) {
SimpleDateFormat sdf = new
SimpleDateFormat("d.M.yyyy");
Date date;
try {
date = sdf.parse((String) object);
setYourDate();
} catch (ParseException ex) {
ex.printStackTrace();
}
}
}
meaning you need to implement the conversion yourself of the Date to any
pattern you want - or you stick using the DateTextField but then need to
set the Locale app-wide to the needed settings the way Francis De
Brabandere posted yesterday at 18:23:
"
You can override newConverterLocator in your Application
@Override
protected IConverterLocator newConverterLocator() {
ConverterLocator locator = new ConverterLocator();
locator.set(java.sql.Date.class, dateConverter);
locator.set(Date.class, dateConverter);
locator.set(Timestamp.class, dateConverter);
return locator;
}
with dateConverter being something like this
public final class DateTimeConverter extends DateConverter {
@Override
public DateFormat getDateFormat(Locale locale) {
return DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
DateFormat.SHORT, locale);
}
}
"
Best Regards
Korbinian
Onno Scheffers schrieb:
Hi,
how can I get the wicket.extensions.markup.html.datepicker.DateFormat
(Wicket 1.2.6) to use a custom DateFormat? I keep getting validation
problems as soon as I try to switch to another DateFormat.
HTML:
<input wicket:id="date" type="text" maxlength="10" /><span
wicket:id="datePicker" />
Java:
TextField dateField = new TextField("date", Date.class);
dateField.setRequired(true);
add(dateField);
DatePicker dp = new DatePicker("datePicker", dateField);
dp.setDateConverter(new DateConverter() {
public DateFormat getDateFormat(Locale locale) {
return new SimpleDateFormat("d-M-yyyy");
}
});
add(dp);
When I leave out the call to setDateConverter, the default format seems
to be MM/dd/yyyy for me.
When setting the DateConverter like I did in the above code, the format
seems to switch from MM/dd/yyyy to dd-MM-yyyy (instead of the expected
d-M-yyyy?). So when I pick september 19th for example, it fills in
17-09-2007 into the TextField, but when I submit that value I get:
'17-09-2007' is not a valid Date.
Only '9/17/2007' or '09/17/2007' are accepted, which is weird since the
DatePicker now puts a value into the textfield which is known to be
invalid?
I also tried providing a DatePickerSettings object that overrides the
getIfFormat(Locale) method to always return "%d-%m-%Y", but that didn't
help either.
- Onno
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]