thats really nice - would you put it on the wiki?
Cheers,
Ron


Geoff Callender wrote:
The minDate and maxDate validators are not portable across application servers or locales. For example minDate=7/1/2005 is accepted by Tomcat but JBoss will reject it because it expects something like minDate=Sep 1 2005 (see http://thread.gmane.org/gmane.comp.java.tapestry.user/28533)

So I wrote portable alternatives that ALWAYS expect a yyyy-MM-dd string. They're called IsoMinDate and IsoMaxDate. Suggestions to improve them are very welcome.

-- Here's how you might use them in your html:

validators=
"validators:required,isoMinDate=1999-01-01,isoMaxDate=2069-12-31"

-- eg.

<input jwcid="@DatePicker" value="ognl:order.date"
translator="translator:date,pattern=dd MMM yyyy" displayName="Order date" validators="validators:required,isoMinDate=1970-01-01,
isoMaxDate=2069-12-31">1 Sep 2005</input>

-- Here's the java for one of the custom validator, IsoMinDate. It extends and uses MinDate, but it accepts a String and parses it the way we like.

package mypackage;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.tapestry.form.validator.MinDate;

public class IsoMinDate extends MinDate {
   private static final String defaultFormatStr = "yyyy-MM-dd";
private static final DateFormat defaultDateFormat = new SimpleDateFormat(defaultFormatStr);

   public void setIsoMinDate(String isoMinDate) {
      try {
         Date date = defaultDateFormat.parse(isoMinDate);
         super.setMinDate(date);
      }
      catch (ParseException e) {
throw new IllegalArgumentException("Value received for isoMinDate is \"" + isoMinDate
           + "\" which does not match format \"" + defaultFormatStr + "\".", e);
      }
   }

}

-- The validators have to be registered with HiveMind. Create or modify WEB-INF/hivemodule.xml to something like this:

<?xml version="1.0"?>

<module id="mystuff" version="1.0.0" package="mypackage">
   <contribution configuration-id="tapestry.form.validator.Validators">
<validator name="isoMinDate" configurable="true" class="mypackage.IsoMinDate"/>
   </contribution>
   <contribution configuration-id="tapestry.form.validator.Validators">
<validator name="isoMaxDate" configurable="true" class="mypackage.IsoMaxDate"/>
   </contribution>
</module>

-- That's it.  I hope this helps whomever.

Geoff


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