You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by david joffrin <da...@hotmail.com> on 2005/04/19 23:33:35 UTC

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="@com.etil.sudetp.presentation.utils.Display@DATEFORMAT"/>
        <set-property name="invalidDateFormatMessage" 
expression="@com.etil.sudetp.presentation.ErrorIds@INVALID_DATE"/>
    </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: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Date formatting validation "strange" behavior

Posted by Bryan Lewis <br...@maine.rr.com>.
A small correction... I provide my own _non_lenient date formatter.

----- Original Message ----- 
From: "Bryan Lewis" <br...@maine.rr.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Tuesday, April 19, 2005 8:38 PM
Subject: Re: Date formatting validation "strange" behavior


> 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="@common.CDate@standardDateFormat()"/>
>      *    </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" <da...@hotmail.com>
> To: <ta...@jakarta.apache.org>
> 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="@com.etil.sudetp.presentation.utils.Display@DATEFORMAT"/>
> >         <set-property name="invalidDateFormatMessage"
> > expression="@com.etil.sudetp.presentation.ErrorIds@INVALID_DATE"/>
> >     </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: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 

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


Re: Date formatting validation "strange" behavior

Posted by Bryan Lewis <br...@maine.rr.com>.
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="@common.CDate@standardDateFormat()"/>
     *    </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" <da...@hotmail.com>
To: <ta...@jakarta.apache.org>
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="@com.etil.sudetp.presentation.utils.Display@DATEFORMAT"/>
>         <set-property name="invalidDateFormatMessage"
> expression="@com.etil.sudetp.presentation.ErrorIds@INVALID_DATE"/>
>     </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: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


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


Date formatting validation "strange" behavior - Reposting

Posted by david joffrin <da...@hotmail.com>.
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="@com.etil.sudetp.presentation.utils.Display@DATEFORMAT"/>
        <set-property name="invalidDateFormatMessage"
expression="@com.etil.sudetp.presentation.ErrorIds@INVALID_DATE"/>
    </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: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org