Java Reference
In-Depth Information
Figure 6.8: Using a tag error renderer
6.3
Changing the Text of Error Messages
When a validation error occurs, Stripes constructs an error message
based on the type of validation that failed, the name of the field, and
the value entered by the user. Although this gives messages that are
quite reasonable, we can change the text in two ways: by changing
the field label and keeping the rest of the text or by changing the text
completely. Let's start with using different field labels.
Changing Field Labels
Stripes constructs a field label by taking the name of the field and sepa-
rating words based on dots (.) and uppercase letters. For example, "con-
tact.phoneNumber" becomes "Contact Phone Number" . This label replaces
the {0} token in an error message, while {1} is replaced by the value
entered by the user. So if the user enters 555 in the contact.phoneNumber
field, the following message:
{1} is not a valid {0}
becomes the following:
555 is not a valid Contact Phone Number.
The label you want to appear in an error message may not corre-
spond to the name of the property. I'm sure you don't want to change
property names just for labeling purposes. Instead, you can use the
label= attribute of @Validate , or you can define the label in the StripesRe-
sources.properties file. Let's see how each technique works by changing
the labels for the fields of the Contact class.
 
 
 
 
Search WWH ::




Custom Search