You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "Rao Archana (HCTM/ETA)" <Ar...@us.bosch.com> on 2009/06/17 23:39:13 UTC

Wicket Date Field Validation

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

Re: Wicket Date Field Validation

Posted by wicketQ <ar...@us.bosch.com>.
Hi Matt,

yay!! It works!!

Thank you very much!




Matthias Keller wrote:
> 
> 
> Rao Archana (HCTM/ETA) wrote:
>> 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.
>> (...)
>> 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.
>> (...)
>>   
> Possibly the simplest approach would be to use a regular expression that 
> allows an empty string like making the whole expression optional by 
> surrounding it with paranthesis and adding the optional operator '?' 
> after it. This allows the empty string OR a valid date but nothing else:
> dateFormat = "^((\\d{1,2})/(\\d{1,2})/(\\d{4}))?$";
> 
> Matt
> 
> -- 
> matthias.keller@ergon.ch  +41 44 268 83 98
> Ergon Informatik AG, Kleinstrasse 15, CH-8008 Zürich
> http://www.ergon.ch
> ______________________________________________________________
> e r g o n    smart people - smart software
> 
> 
> 
>  
> 

-- 
View this message in context: http://www.nabble.com/Wicket-Date-Field-Validation-tp24087119p24099701.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Wicket Date Field Validation

Posted by Matthias Keller <ma...@ergon.ch>.
Rao Archana (HCTM/ETA) wrote:
> 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.
> (...)
> 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.
> (...)
>   
Possibly the simplest approach would be to use a regular expression that 
allows an empty string like making the whole expression optional by 
surrounding it with paranthesis and adding the optional operator '?' 
after it. This allows the empty string OR a valid date but nothing else:
dateFormat = "^((\\d{1,2})/(\\d{1,2})/(\\d{4}))?$";

Matt

-- 
matthias.keller@ergon.ch  +41 44 268 83 98
Ergon Informatik AG, Kleinstrasse 15, CH-8008 Zürich
http://www.ergon.ch
______________________________________________________________
e r g o n    smart people - smart software