commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton" <niall.pember...@gmail.com>
Subject Re: [VALIDATOR] property order using extends attribute
Date Fri, 09 Mar 2007 09:08:39 GMT
On 3/9/07, Strachan, Paul <Paul.Strachan@det.nsw.edu.au> wrote:
> Hi,
>
> using validator 1.2.0 and struts 1.2.9 is there any way to control the order of validation
error messages output on the screen?

I would recommend upgrading to the latest Validator 1.3.1 release -
its compatible with Struts 1.2.9 and has a number of bug fixes:

http://jakarta.apache.org/commons/validator/changes-report.html

> for example:
>
> <form name="MyForm">
>   <field property="firstName" depends="required">
>     <arg key="firstName.label" resource="true"/>
>   </field>
>   <field property="lastName" depends="required">
>     <arg key="lastName.label" resource="true"/>
>   </field>
>   <field property="dateOfBirth" depends="date">
>     <arg key="dateOfBirth.label" resource="true"/>
>   </field>
> </form>
>
> This example displays:
> o First name is required
> o Last name is Required
> o Date of Birth is invalid
>
>
> Now if I change the validation as follows:
>
> <form name="MyForm_fatal">
>   <field property="dateOfBirth" depends="date">
>     <arg key="dateOfBirth.label" resource="true"/>
>   </field>
> </form>
>
> <form name="MyForm" extends="MyForm_fatal">
>   <field property="firstName" depends="required">
>     <arg key="firstName.label" resource="true"/>
>   </field>
>   <field property="lastName" depends="required">
>     <arg key="lastName.label" resource="true"/>
>   </field>
> </form>
>
> When I validate against "MyForm" it displays:
> o Date of Birth is invalid
> o First name is required
> o Last name is Required
>
> Is it possible to control the order so that the date of birth message is displayed after
the last name. Possibly an optional attribute (int) on the <field> element ?

Validator validates the fields in the order you specify them in your
validation.xml - and Struts displays messages in the order they are
added. So to control the order of messages specify the fields in the
order you want to see the messages. Alternatively you can control
messages for individual fields in struts using the "property"
attribute either on the <html:errors/> or <html:messages/> tag - for
an example see here:

http://www.niallp.pwp.blueyonder.co.uk/HelpTagsErrorsAndMessages.html#section5

Niall

> Thanks,
>
> Paul

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message