11.6 Internationalizing the Validation


The Validator framework uses the application resource bundles to generate error messages for both client-side and server-side validation. Thus, from an I18N perspective, much of the work for displaying language-specific messages to the user is included within the framework.

It was mentioned earlier that the formset element in the validation.xml file supports attributes related to internationalization. Those attributes are language, country, and variant. As you know, these attributes correspond to the java.util.Locale class. If you don't specify these attributes, the default Locale is used.

If your application has I18N validation requirements, you will need to create separate formset elements, one for each Locale that you need to support for each form that you need to validate. For example, if your application has to support validation for a form called registrationForm for both the default locale and the French locale, the validation.xml file should contain two formset elements one for the default locale and the other for the French locale. This is shown in the following fragment:

<formset>   <form name="registrationForm">     <field        property="firstName"       depends="required,mask,minLength">       <arg0 key="registrationForm.firstname.displayname"/>       <var>         <var-name>mask</var-name>         <var-value>^\w+$</var-value>       </var>       <var>         <var-name>minLength</var-name>         <var-value>5</var-value>       </var>     </field>       </form> </formset> <formset language="fr">   <form name="registrationForm">   <field     property="firstName"     depends="required,mask,minLength">     <arg0 key="registrationForm.firstname.displayname"/>     <var>       <var-name>mask</var-name>       <var-value>^\w+$</var-value>     </var>       </field>   </form> </formset>



Programming Jakarta Struts
Programming Jakarta Struts, 2nd Edition
ISBN: 0596006519
EAN: 2147483647
Year: 2003
Pages: 180

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net