|
Struts validation
mechanism can use caption to provide user friendly messages for the validation
errors.
However, there are
implementation steps that must be taken for these captions to be included in
such messages.
The label tag, within
the content source, would capture the association between an element and its
label.
The usefulness of
entering the caption in this field is that it provides the first step towards
externalization.
The first step
towards this process is the designation of keys for these captions. The scheme
for arriving at this caption would be based on the convention used by the
organization or group. An example of such entry is shown below.
{categoryForm.categoryName}
The label would be
reflected in the external file, in a form similar to this.
categoryForm.categoryName=Category Name
The default name for
the external file is:
MessageResources.properties
As mentioned earlier,
there would be multiples of these files for different languages. There is a
convention for the variations in the file names to differentiate language and
country, or locales. Example is shown below for the French language variation.
MessageResources_fr.properties
The steps above,
would externalize the label strings. To use this externalized strings, and
allow internationalization, the literal strings must be replaced with the bean
message tag, which would involve converting the source content from the
following:
<label for="categoryName">Category Name</label>
To the following:
<label for="categoryId">
<bean:message key ="categoryData.categoryName"/>
</label>
As could be seen under the subject of element validators,
the caption is also part of the data that are reflected in the validation
configuration file.
|