You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "tarek.nabil" <ta...@isoft.ae> on 2005/05/05 12:40:25 UTC
Date validator does not ignore nulls
Hi everyone,
For some sort of reason, I'm using Struts version 1.1b2. I have a search
screen where the user can search using some date fields. I put the
following field declaration in my validations.xml file
<field property="endDate" depends="date">
<arg0 key="forms.project.endDate"/>
<var>
<var-name>datePattern</var-name>
<var-value>${dateFormat}</var-value>
</var>
</field>
The date validator is declared as follows in my validator-rules.xml
(without the JavaScript)
<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"
depends="required"
msg="errors.date"
jsFunctionName="DateValidations">
Although the validator declares that it depends on required, so (as far
as I understand) that means it should not be triggered if the value is
null or blank. Nevertheless, it is, and it shows the error that the date
is invalid. I checked the source for the class that performs the
validation, and obviously it adds the error to the errors collection if
the value is null or blank. But I think it's not supposed to even get
called, because in the declaration of the validator, it says it depends
on required.
Is this a bug in this old version, or am I doing something wrong?
Any help is appreciated.
Thanks,
Tarek Nabil
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Date validator does not ignore nulls
Posted by Dave Newton <ne...@pingsite.com>.
tarek.nabil wrote:
> <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"
> depends="required"
> msg="errors.date"
> jsFunctionName="DateValidations">
>
>Although the validator declares that it depends on required, so (as far
>as I understand) that means it should not be triggered if the value is
>null or blank. Nevertheless, it is, and it shows the error that the date
>is invalid. I checked the source for the class that performs the
>validation, and obviously it adds the error to the errors collection if
>the value is null or blank. But I think it's not supposed to even get
>called, because in the declaration of the validator, it says it depends
>on required.
>
>
"Required" means the value must not be blank or null, right? So if a
validation depends on "required" that means that the value can't be
blank or null. So it _should_ be triggered on a blank or null.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org