This tool deals with Struts error messages. Errors may stem from the validation of a submitted form or from the processing of a request. If there are errors, they are made available to the view to render. A few important aspects about errors are:
property
that describes the category of
error. This allows the view designer to place error messages precisely where an
error occurred. For example, errors that apply to the entire page can be rendered
at the top of the page, errors that apply to a specific input field can be rendered
next to this input field. Several methods of this tool provide a parameter
property
that allows to select a specific category of errors to operate
on. Without the property
parameter, methods operate on all error messages.See the Struts User's Guide, section Building View Components for more information on this topic.
true
if there are errors queued, otherwise false
.
true
if there are error messages queued. false
otherwise.
Calling exist()
without the property
parameter checks for error messages of
any category. The property
parameter can be used to limit the check to
error messages of a specific category.
Calling getSize()
without the property
parameter returns the total
number of queued error messages. The property
parameter can be used to
obtain the number of queued error messages for a specific category.
$errors.get($errors.globalName)
The following example shows a macro to render the error messages:
This produces output similar to the following:
java.util.List
of java.lang.String
.
If no error messages exist for the specified category,
null
is returned.
If the message resources are lacking an error message for a
particular message key, the key itself is used as an error message
and a warning is logged.
The following example shows a macro to render the error messages for a particular category of errors:
This produces output similar to the following:
String
is returned.
This method renders the queued error messages as a list. If the method
is called without a parameter, all queued errors are rendered. With the
parameter property
the list of rendered messages can be
limited to a specific category of errors. Error message texts
are looked up in the message resources. If a message text
cannot be found, the message key will be displayed instead.
The method expects a message header, a message footer, a message prefix
and a message suffix to be defined in the message resources. The corresponding
message keys are errors.header
, errors.footer
,
errors.prefix
and errors.suffix
.
Assuming that the message resources contain the following definitions:
an error message would be rendered as follows: