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"> ...
Get Programming Jakarta Struts, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.