If you want the validator to pick it up based on the Form name (as opposed to the Action Path name) you should use a ValidatorForm instead of a ValidatorActionForm.
You might need to use datePatternStrict too. There's some (or used to be anyway) some weirdness with the javascript not catching it unless you used it. > -----Original Message----- > From: Michael Oliver [mailto:[EMAIL PROTECTED] > Sent: Thursday, March 03, 2005 12:58 PM > To: struts-user@jakarta.apache.org > Subject: Validator date problem > > I have read the Validator User Guide as well as chapter 12 in Struts In > Action. > > I am trying to get a validator to validate a date field with no success. > When I post the form with "02/30/2005" or "02/33/2005" or "02/30/xyz" > it goes through without catching the bad date. > > If however I do not put a 'name' field entry or a date entry at all, I > do get the javascript alert "required field" as expected. > > Server side debugging, during the SaveAssignmentForm action the > AssignmentForm.validate() is called and the ActionErrors errs value is > not null which tells me it tried to validate, but there are no messages. > > > I have used SimpleDateFormat.parse("02/30/2005") in a separate test > script and it throws an exception as expected. > > Using Struts 1.1 > > Snippets from my sources... > > --- > AssignmentForm.java > > public class AssignmentForm extends ValidatorActionForm { > > private String assignedDate; > . > > public ActionErrors validate(ActionMapping actionMapping, > HttpServletRequest request) { > ActionErrors errs = super.validate(actionMapping, > request); > > return errs; > } > . > standard getter and setter for assignedDate. > > --- > AssignmentForm.jsp > > <head> > <html:javascript formName="AssignmentForm"/> > ... > <html:form action="SaveAssignmentForm" > onsubmit="validateAssignmentForm(this)"> > <html:text property="name" maxlength="255" size="40"/> > <html:text property="assignedDate"></html:text> > > ---- > > struts-config.xml > > <action name="AssignmentForm" path="/SaveAssignmentForm" > scope="request" > type="com.alarius.assignments.actions.SaveAssignmentForm" > validate="true"> > <forward name="showAssignmentList" path="/ShowAssignmentList.do"/> > </action> > ... > <plug-in className="org.apache.struts.validator.ValidatorPlugIn"> > <set-property property="pathnames" > value="/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml"/> > </plug-in> > > --- > validator-rules.xml - unchanged from distribution > --- > validation.xml > > <formset> > > <!-- AssignmentForm --> > <form name="AssignmentForm"> > <field property="name" depends="required"> > <arg0 key="AssignmentForm.name" /> > </field> > <field property="assignedDate" depends="required,date"> > <arg0 key="AssignmentForm.assignedDate" /> > <var> > <var-name>datePattern</var-name> > <var-value>MM/dd/yyyy</var-value> > </var> > </field> > </form> > <!-- end AssignmentForm --> > > </formset> > > What did I miss or where should I look now. > > > Michael Oliver > Alarius Systems LLC > 3325 N. Nellis Blvd, #1 > Las Vegas, NV 89115 > Phone:(702)643-7425 > Fax:(520)844-1036 > *Note new email changed from [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]