|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
@Retention(value=RUNTIME) @Documented @Target(value={FIELD,METHOD}) public @interface MessageParam
Adds information to a field of an exception about which parameter in a message it provides information.
ParentMessageParam
Optional Element Summary | |
---|---|
String |
value The index of the place holder in the message text the field provides information for. |
public abstract String value
If the index is not sufficient, because there is a certain property within the referenced entity/value object, an OGNL (Object-Graph Navigation Language) expression is added to access a particular value. The basic syntax for this is
Syntax: Index with OGNL expression
index:ognl-expression
Index with OGNL Expression
1:user.name
Here we show some examples on how this annotation is used.
Example 1
You want to include the value of a property.
Annotation: Index without OGNL Path
@MessageParam("0") protected final String name; @MessageParam("1") protected final String description;
Message bundle content
msgX=For ''{0}'' this is the description: {1}
The placeholder at index zero (0
) is replaced by the name the placeholder at index one (1
) is replaced by the description.
Example 2
You want to display the canonical name of a referenced class.
Annotation: Index and OGNL Path
@MessageParam("0:canonicalName") protected final Class<?> clazz;
Message bundle content
msgY=The class with name '' 0\
The placeholder at index zero (0
) is replaced by the canonical name
of the referenced class.
Example 3
If several properties of a referenced entity are to be displayed at different indices, separate them by commas.
Annotation: Several Properties
@MessageParam("0:user.name,2:user.id,3:description") protected final Context context; @MessageParam("1") protected final Date date;
Message bundle content
msgZ= {1,date} at {1,time}: For user ''{0}'' (ID={2}) this is the description: {3}
This uses the user's name
for the placeholder with index 0
, the identifier (id
) of the user at index 2
and the descriptive text of the context ( description
) at index 3
. The Context
class in this example provides a property user
and description
, the user provides the properties name
and id
. The date provides information for index 1
to show that the indices of several message parameters are not required to be consecutive.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |