Java Reference
In-Depth Information
Accessing the List of Messages
The <s:messages> and <s:errors> tags take care of displaying
messages for you. However, nothing stops you from accessing
the list of messages directly and doing whatever you want with
it. Messages are stored in ActionBeanContext and are available
with getMessages ( ) for information messages and getValidation-
Errors ( ) for error messages, so you can easily access them in a
JSP with an expression. For example:
<c:if test="${not empty actionBean.context.messages}">
There are ${fn:length(actionBean.context.messages)}
information messages.
</c:if>
<c:if test="${not empty actionBean.context.validationErrors}">
There are ${fn:length(actionBean.context.validationErrors)}
error messages.
</c:if>
The first way is to add label= attributes to @Validate annotations:
Download email_12/src/stripesbook/action/ContactFormActionBean.java
@ValidateNestedProperties({
@Validate(field="firstName", maxlength=25, label="Given name"),
@Validate(field="lastName",
minlength=2, maxlength=40,
label="Surname"),
@Validate(field="email", required= true , on="save",
converter=EmailTypeConverter. class , label="E-mail"),
@Validate(field="birthDate", expression="${this < today}",
label="Date of birth"),
@Validate(field="phoneNumber", label="Telephone number")
})
@Override
public void setContact(Contact contact) {
super .setContact(contact);
}
These labels will be used for {0} tokens in error messages. Now, the
following:
{1} is not a valid {0}
will be displayed as this:
555 is not a valid Telephone number.
Field labels are also used in the <s:label> tag. Back on page 127 , we
 
 
Search WWH ::




Custom Search