You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by trsvax <tr...@gmail.com> on 2012/08/20 22:10:40 UTC

DateField appears to use lenient date parser (Bug?)

I have a DateField for entering Date of Birth. If you enter 00/01/2000 the
database ends up with 12/01/1999 which is not at all what I would want since
00/01/2000 is (should be) an invalid date. The Java documentation says this:

By default, parsing is lenient: If the input is not in the form used by this
object's format method but can still be parsed as a date, then the parse
succeeds. Clients may insist on strict adherence to the format by calling
setLenient(false). 

It seems to me DateField should probably call setLenient(false) or at the
very least provides a lenient parameter to allow setting it to false.
Personally I think the default should be strict.

Should I create as issue for this? It would be nice if this could be in the
next release because from my perspective this is a major problem. I don't
mind providing the patch.

Thanks
Barry



--
View this message in context: http://tapestry.1045711.n5.nabble.com/DateField-appears-to-use-lenient-date-parser-Bug-tp5715631.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: DateField appears to use lenient date parser (Bug?)

Posted by trsvax <tr...@gmail.com>.
While I think that would fix the problem having the DateField use the Lenient
parser seems wrong to me. Would it make sense for the Integer validator to
accept '123!4' as 12314? If the purpose is to validate dates then that's
what it should do.

So I suppose a different fix is to replace the type converter with one that
calls setLenient(false).

I guess my question is what's the point of the default being lenient?



--
View this message in context: http://tapestry.1045711.n5.nabble.com/DateField-appears-to-use-lenient-date-parser-Bug-tp5715631p5715637.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: DateField appears to use lenient date parser (Bug?)

Posted by trsvax <tr...@gmail.com>.
This did seem like the obvious solution but it does not fix the problem
either. If you enter a date of

01/01/200q

The date you end up with is Jan, 1 200

I had to add a regexp 
courtDate-regexp=\\d\\d/\\d\\d/\\d\\d\\d\\d
create-courtDate-regexp-message=Must be mm/dd/yyyy

To make it work correctly. This seems like way too much work and error prone
to get a Date to validate correctly.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/DateField-appears-to-use-lenient-date-parser-Bug-tp5715631p5715674.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: DateField appears to use lenient date parser (Bug?)

Posted by Robert Zeigler <ro...@roxanemy.com>.
Why not use the format parameter? Although the typical use is to specify the format with a string and allow type-coercion to generate the format for you, the underlying parameter is DateFormat, and you can pass one in directly and have tapestry use it. Just be aware of thread-safety: whichever component is using the DateField needs to create a unique unique DateFormat object for each thread.

Robert

On Aug 20, 2012, at 8/203:10 PM , trsvax wrote:

> I have a DateField for entering Date of Birth. If you enter 00/01/2000 the
> database ends up with 12/01/1999 which is not at all what I would want since
> 00/01/2000 is (should be) an invalid date. The Java documentation says this:
> 
> By default, parsing is lenient: If the input is not in the form used by this
> object's format method but can still be parsed as a date, then the parse
> succeeds. Clients may insist on strict adherence to the format by calling
> setLenient(false). 
> 
> It seems to me DateField should probably call setLenient(false) or at the
> very least provides a lenient parameter to allow setting it to false.
> Personally I think the default should be strict.
> 
> Should I create as issue for this? It would be nice if this could be in the
> next release because from my perspective this is a major problem. I don't
> mind providing the patch.
> 
> Thanks
> Barry
> 
> 
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/DateField-appears-to-use-lenient-date-parser-Bug-tp5715631.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


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