Here's the same post with arguably better names for the validators - 
minDateISO and maxDateISO instead of isoMinDate and isoMaxDate...


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 minDateISO and maxDateISO.  Suggestions to improve them are
very welcome.
 
-- Here's how you might use them in your html:
 
validators=
"validators:required,minDateISO=1999-01-01,maxDateISO=2069-12-31"
 
-- eg.
 
<input jwcid=" <at> DatePicker" value="ognl:order.date"
translator="translator:date,pattern=dd MMM yyyy" displayName="Order date"
validators="validators:required,minDateISO=1970-01-01,
maxDateISO=2069-12-31">1 Sep 2005</input>
 
-- Here's the java for one of the custom validator, minDateISO.  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 MinDateISO extends MinDate {
   private static final String isoFormatStr = "yyyy-MM-dd";
   private static final DateFormat isoDateFormat =
      new SimpleDateFormat(isoFormatStr);
 
   public void setMinDateISO(String minDateISO) {
      try {
         Date date = isoDateFormat.parse(minDateISO);
         super.setMinDate(date);
      }
      catch (ParseException e) {
         throw new IllegalArgumentException("Value received for minDateISO is 
\""
           + minDateISO
           + "\" which does not match format \"" + isoFormatStr + "\".", 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="minDateISO" configurable="true"
         class="mypackage.MinDateISO"/>
   </contribution>
   <contribution configuration-id="tapestry.form.validator.Validators">
      <validator name="maxDateISO" configurable="true"
         class="mypackage.MaxDateISO"/>
   </contribution>
</module>
 
-- That's it.  I hope this helps whomever.
 
Geoff



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

Reply via email to