I have a situation where the DateTextField and DatePicker are not using the
same date pattern although I set them to the same value.
If I have an existing date in the model then it is formatted correctly and
that date is also inherited correctly when the DatePicker opens. When I then
select a different date in the DatePicker the correct date value is returned
to the DateTextField but the format it wrong. Then if I submit the form I
get an error on the DateTextField.
For example, if I select a date of "28/Mar/2008" in the DatePicker it gets
returned to the DateTextField as "28/3/2008".
Any ideas?
import org.apache.wicket.datetime.markup.html.form.DateTextField;
import org.apache.wicket.datetime.PatternDateConverter;
import org.apache.wicket.extensions.yui.calendar.DatePicker;
...
public class DateField extends Panel {
public DateField(
String id,
boolean readonly,
IField field,
IModel model
)
{
super( id );
final String dateFormat = "dd/MMM/yyyy";
PatternDateConverter pdc = new PatternDateConverter( dateFormat,
true );
DateTextField dtf = new DateTextField( "textValue", new
NamedAccessorModel( model, field.getModelName( ) ), pdc );
add( dtf );
DatePicker dp = new DatePicker( ) {
protected boolean enableMonthYearSelection( ) {
return true;
}
protected String getDatePattern( ) {
return dateFormat;
}
};
dtf.add( dp );
}
}