Java Reference
In-Depth Information
discussed using <s:label> for labels so that Stripes would automati-
cally highlight them when the corresponding field was in error. Now
that the text is in @Validate(label=) , there's no need to repeat it in the
body of the <s:label> tag. We can remove the text from the body and
use empty <s:label/> tags:
Download email_12/web/WEB-INF/jsp/contact_form.jsp
<td><s:label for="contact.phoneNumber"/> : </td>
<td>
<s:text name="contact.phoneNumber" formatType="dashes"/>
</td>
<td><s:errors field="contact.phoneNumber"/></td>
Stripes automatically uses the label that we defined in @Validate(label=)
as the text of the <s:label/> tag. In the previous example, Telephone
number: will appear in front of the text field. The label will be displayed
normally when all is well and will be highlighted when the field is in
error.
Using the label= attribute is quick and easy but limited. The text is not
localizable, and the labels are limited to the form linked to the action
bean—the contact form, in this example.
The second way of changing field labels that are used in error messages
and the <s:label/> tag is with the resource bundle. This method, which
overrides any existing @Validate(label="...") definitions, allows you to use
the labels everywhere in the application. They also make the labels
localizable, as we'll see in Chapter 11 , Parlez-Vous Français? Making It
Multilingual, on page 218 . We define a field label by using the field name
as a key in StripesResources.properties :
Download email_13/res/StripesResources.properties
contact.firstName=FIRST NAME
contact.lastName=LAST NAME
contact.email=EMAIL
contact.phoneNumber=PHONE NUMBER
contact.birthDate=BIRTH DATE
This would display field labels in uppercase letters. We can now use
these labels everywhere—for example, in the contact view with empty
<s:label/> tags:
Download email_13/web/WEB-INF/jsp/contact_view.jsp
<tr>
<td class="label"><s:label for="contact.firstName"/> : </td>
<td class="value"> ${actionBean.contact.firstName} </td>
</tr>
 
Search WWH ::




Custom Search