I believe you're seeing the "lenient" behavior of the standard Java date
formatter; it happily accepts 28 as a month input and converts it to two
years and four months. I provide my own lenient date formatter:
/**
* This is expected to be our typical date format. A Tapestry
* dateValidator, for example, could be specified as:
*
* <bean name="dateValidator"
class="org.apache.tapestry.valid.DateValidator">
* <set-property name="format"
expression="@[EMAIL PROTECTED]()"/>
* </bean>
*
* The main reason for it is setLenient(false). It's silly to
auto-convert an
* entry like 13/33/2002 to 02/02/2003.
*/
public static DateFormat standardDateFormat()
{
// Don't try to cache a singleton SimpleDateFormat. It's not
// thread-safe.
DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
format.setLenient(false);
return format;
}
----- Original Message -----
From: "david joffrin" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, April 19, 2005 5:33 PM
Subject: Date formatting validation "strange" behavior
> OK, so I have the following:
>
> .page:
> <bean name="dateValidator"
> class="org.apache.tapestry.valid.DateValidator">
> <set-property name="required" expression="false"/>
> <set-property name="format"
> expression="@[EMAIL PROTECTED]"/>
> <set-property name="invalidDateFormatMessage"
> expression="@[EMAIL PROTECTED]"/>
> </bean>
> <component id="validity" type="ValidField">
> <binding name="value" expression="validity"/>
> <binding name="validator" expression="beans.dateValidator"/>
> <static-binding name="displayName" value="Validity:"/>
> </component>
>
> .html:
> <tr>
> <td bgcolor="#EAEAF7"></td>
> <td bgcolor="#EAEAF7">
> <b><span jwcid="@FieldLabel"
> field="ognl:components.validity">Validity:</span></b><br/>
> <small>(dd/mm/yyyy)</small>
> </td>
> <td><input jwcid="validity" type="text" size="10"/></td>
> </tr>
>
> .java:
> IValidationDelegate delegate = getValidationDelegate();
>
> // There were some UI validation errors!
> if (delegate.getHasErrors())
> return;
>
> public class Display {
> public static final DateFormat DATEFORMAT = new
> SimpleDateFormat("dd/MM/yyyy");
> }
>
>
> If I enter a date like 04/28/1990.... no validation is happening and my
date
> is transformed to 04/04/1992!!!
> What shall I do to implement this validation dd/mm/yyyy.
>
> Thanks.
> David
>
>
>
> ---------------------------------------------------------------------
> 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]