Hi,

I am working on date fields and have problems with the validation. I
have referred to the link below which helped me.

http://www.nabble.com/Strict-4-digit-year-for-DateTextField--td18656889.
html


So I have subclassed the PatternDateConverter and have set the pattern
as,
dateFormat = "^(\\d{1,2})/(\\d{1,2})/(\\d{4})$";

I have 2 date fields, start_date and end_date. The start_date is a
required field and the end_date is not.

.... some code

pdc = new
StrictPatternDateConverter(DateUtil.getDateFormatOnLocale(getLocale()),
false);

.... more code

startDateField = DateTextField.withConverter("startDate", new
PropertyModel(this, "startDate"), pdc);
startDateField.add(new TMPDatePicker());
form.add(startDateField);        
endDateField = DateTextField.withConverter("endDate", new
PropertyModel(this, "endDate"), pdc);
endDateField.add(new TMPDatePicker());
form.add(endDateField);        

.... more code

This works fine ie it does not allow entry of "03/03/09" or
"03/03/-2009"

BUT, the end_date becomes a required field. I have to enter the end_date
to click 'Save'. Else it complains that an invalid date has been
entered.
But my end_date is not a required field.

So if I replace it with,

endDateField = DateTextField.forDatePattern("endDate",
DateUtil.getDateFormatOnLocale(getLocale()));
endDateField.withConverter("endDate", pdc);
endDateField.add(new TMPDatePicker());

It allows, "03/03/-2009" and "03/03/09". Why does it allow the '-' sign.
It computes it to a value and displays a year.

My application has several date fields and I need to validate them.

I am a newbie to Wicket and have looked up the archive quite a bit to
find a solution.
Can someone please tell me a solution to my date validation problem?

Thanks very much

Reply via email to