You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Binil Thomas <bi...@gmail.com> on 2007/03/15 07:22:54 UTC
[S2] Validating two dates
Hi all,
I searched the archives on this, but could not find an answer - hence I am
posting it here.
I have two date fields on my form. I want to validate that the first is
always on or before the second. I want the error message to show next to the
second date field.
In my Action-alias-validation.xml, I tried:
<validator type="expression">
<param name="expression">firstDate.after(secondDate)</param>
<message>First date cannot be after second date</message>
</validator>
This does not run during AJAX field validations.
I also tried:
<field name="secondDate">
<field-validator type="required">
<message>Second date cannot be empty</message>
</field-validator>
<field-validator type="date">
<param name="min">${firstDate}</param>
<message>Second date has to be on or later than first date
${firstDate}</message>
</field-validator>
</field>
This throws an error on the server-side:
WARNING: Caught OgnlException while setting property 'min' on type
'com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator'
java.lang.NoSuchMethodException: setMin(java.lang.String)
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:824)
at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:978)
at
ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:75)
...
DateRangeFieldValidator expects the min parameter to be a date, and I think
the ${firstDate} construct did not work.
Can someone please guide how to accomplish this?
Thanks,
Binil
--
View this message in context: http://www.nabble.com/-S2--Validating-two-dates-tf3406568.html#a9489157
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [S2] Validating two dates
Posted by Binil Thomas <bi...@gmail.com>.
Hi all,
I got it working using the fieldexpression validator.
<field-validator type="fieldexpression">
<param name="expression">
firstDate.before(secondDate) || firstDate.equals(secondDate)
</param>
<message>Second date has to be on or later than first date</message>
</field-validator>
Posting this here so that it might be helpful to someone. Please see
http://struts.apache.org/2.0.6/docs/fieldexpression-validator.html - not
sure why I missed it!
Thanks,
Binil
Binil Thomas wrote:
>
> Hi all,
> I searched the archives on this, but could not find an answer - hence I am
> posting it here.
>
> I have two date fields on my form. I want to validate that the first is
> always on or before the second. I want the error message to show next to
> the second date field.
>
--
View this message in context: http://www.nabble.com/-S2--Validating-two-dates-tf3406568.html#a9532016
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org