Hi Bryan,

Try

  <bean name="maxDateValidator"
class="org.apache.tapestry.form.validator.MaxDate,message={0} must be on
or before {1,date,short}">
       <set name="maxDate" value="@[EMAIL PROTECTED]()"/>
   </bean>

Assuming the message conforms to the standard java.text.MessageFormat class, then it should display the date in the standard short format.

You should also be able to specify a custom format:

{0} must be on or before {1,date,MM/dd/yyyy}

Cheers

Richard

Bryan Lewis wrote:
It's certainly possible to do those things with code, although that
approach seems to be falling out of fashion these days. :-)

#1.  Write a utility method to call instead of java.util.Date().  What I
use:

    public static Date today() {
        return org.apache.commons.lang.time.DateUtils.truncate(new
java.util.Date(), Calendar.DATE);
    }

#2.  I also couldn't see how to tweak the error message elegantly.  Here
are my notes from a couple of months ago:

I can tweak the error message format like so:

    <bean name="maxDateValidator"
class="org.apache.tapestry.form.validator.MaxDate,message={0} must be on
or before {1}">
        <set name="maxDate" value="@[EMAIL PROTECTED]()"/>
    </bean>

But that's not flexible enough.  It still says:

    Last Password Date must be on or before 12/31/05 12:00 AM

when I want:

    Last Password Date must be on or before 12/31/2005

It isn't hard to customize our own subclass of the validator though. Start by
copying the code for org.apache.tapestry.form.validator.MaxDate.java, and
change the buildMessage() method:

    private String buildMessage(ValidationMessages messages,
IFormComponent field) {
        String maxDateFormattedString = // format the maxDate the way we
want

I can't use the shorthand declaration though... can't put code in the
initializer:

    <binding name="validators" value="validators:required,maxDate=today()"/>

So stick with the bean technique.



Martin Carel wrote:

Hi!

There are 2 tweaks I'd like to do with date validations.


Tweak #1

Would there be a way to set the minDate to the beginning of the day
(and thus make the exact time at which it was instanciated irrelevant)?
At this moment, in my page spec, I have:

<bean name="minDate1" class="org.apache.tapestry.form.validator.MinDate">
 <set name="minDate" value="new java.util.Date()"/>
</bean>

Now with my DatePicker component, when I enter today's date, it does
not get through validation, as 2006-02-22 00:00 (the DatePicker's
date) is before 2006-02-22 10:04 (the minDate) for example.


Tweak #2

And is it possible to tweak the validation error message not to
display the time?

Now I have:
Drop off date must be on or after 2006-02-23 10:04.

And I would like:
Drop off date must be on or after 2006-02-23.

Thanks in advance.

/Martin


---------------------------------------------------------------------
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]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to