Axel Stahlhut wrote: > Sorry for posting this one again, but its a bit urgent and maybe i have a chance >marking it as a post concerning [Validator]. > > Validating a Date with the Struts-Validator Framework works fine, but if the field i >want to validate is not a required field and may be empty, the validator always >reports an error, even if if i remove the depends="required" in the >validation-rules.xml. > Do i have to implement the Validator-class in a way that it doesnt validate empty >dates or is there any declarative way to solve this? > Thanks for any help. > > Axel > > This is my validation-rules.xml: > > <validator name="date" > classname="org.apache.struts.util.StrutsValidator" > method="validateDate" > methodParams="java.lang.Object, > org.apache.commons.validator.ValidatorAction, > org.apache.commons.validator.Field, > org.apache.struts.action.ActionErrors, > javax.servlet.http.HttpServletRequest" > msg="errors.date" > jsFunctionName="DateValidations"> > > and the validation.xml: > > <field property="beginEmployment" depends="date"> > <arg0 key="personal.data.beginEmployment" /> > <var> > <var-name>datePattern</var-name> > <var-value>dd.MM.yyyy</var-value> > </var> > </field> > > >
Hi Axel, you can subclass the DynaValidatorForm to override the validator method. There you can check if the date field is empty, something like that public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { String date = null; if (((date = (String) this.get("yourDateField")) == null) || (date.length == 0)) { // do no validation return null; } return super.validate(mapping, request); } Hope this helps. Marco -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>