Java Reference
In-Depth Information
Combining Global and Field-Specific Errors
You can create error messages that are not associated with a
specific field with the
addGlobalError
( ) method of the
Validation-
Errors
class. These global errors will not be displayed if you have
only
<s:errors field="..."/>
tags. Adding the plain <s:errors/> tag
displays global errors but duplicates the field-specific error mes-
sages. To combine the display of global and field errors, add
the
globalErrorsOnly=
"true" attribute to the <s:errors/> tag. This
way, you can display global errors in a group and field-specific
errors next to fields:
<s:form ...>
<s:errors globalErrorsOnly="true"/>
...
<td>Email:</td>
<td><s:text name="contact.email"/></td>
<td><s:errors field="contact.email"/></td>
...
</s:form>
Highlighting the labels and text fields that are in error is now a simple
matter of some CSS code:
input.error {
border: 2px solid #880000;
background-color: #FFDDDD;
}
label.error {
color: #880000;
font-weight: bold;
text-decoration: underline;
}
Notice that both the labels and the fields that are in error are high-
lighted.
If the
error
class is not enough to highlight tags as we require, we can
take full control of how tags are rendered when they are in error by
implementing the
TagErrorRenderer
interface:
public interface
TagErrorRenderer {
void
init(InputTagSupport tag);
void
doBeforeStartTag();
void
doAfterEndTag();
}
Search WWH ::
Custom Search