MessageCodesResolver interface.
Will create two message codes for an object error, in the following order (when
using the prefixed
formatter):
Will create four message codes for a field specification, in the following order:
For example, in case of code "typeMismatch", object name "user", field "age":
This resolution algorithm thus can be leveraged for example to show specific messages for binding errors like "required" and "typeMismatch":
In case of array, List or java. properties,
both codes for specific elements and for the whole collection are
generated. Assuming a field "name" of an array "groups" in object "user":
By default the errorCodes will be placed at the beginning of constructed
message strings. The messageCodeFormatter property can be used to specify an alternative concatenation
format.
In order to group all codes into a specific category within your resource bundles,
e.g. "validation.typeMismatch.name" instead of the default "typeMismatch.name",
consider specifying a prefix to be applied.
| Modifier and Type | Class and Description |
|---|---|
| public static enum | DefaultMessageCodesResolver.
Common message code formats. |
| Modifier and Type | Field and Description |
|---|---|
| public static final String | CODE_SEPARATOR
The separator that this implementation uses when resolving message codes. |
| private static final MessageCodeFormatter | |
| private MessageCodeFormatter | |
| private String |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private void | |
| protected void | buildFieldList(String field, List<String> fieldList)
Add both keyed and non-keyed entries for the supplied |
| protected String | |
| protected String | Returns: the final message code to be returnedthe message code as built by this resolver code)Post-process the given message code, built by this resolver. |
| public String[] | resolveMessageCodes(String
the error code used for rejecting the object errorCode, String the name of the object objectName)Implements org. Build message codes for the given error code and object name. |
| public String[] | Returns: the list of codesthe error code used for rejecting the value errorCode, String the name of the object objectName, String the field name field, Class<?> the field type (may be fieldType)null if not determinable)Implements org. Build the code list for the given code and field: an object/field-specific code, a field-specific code, a plain error code. |
| public void | setMessageCodeFormatter(MessageCodeFormatter formatter)
Specify the format for message codes built by this resolver. |
| public void |
| CODE_SEPARATOR | back to summary |
|---|---|
| public static final String CODE_SEPARATOR The separator that this implementation uses when resolving message codes. | |
| DEFAULT_FORMATTER | back to summary |
|---|---|
| private static final MessageCodeFormatter DEFAULT_FORMATTER | |
| formatter | back to summary |
|---|---|
| private MessageCodeFormatter formatter | |
| prefix | back to summary |
|---|---|
| private String prefix | |
| DefaultMessageCodesResolver | back to summary |
|---|---|
| public DefaultMessageCodesResolver() | |
| addCode | back to summary |
|---|---|
| private void addCode(Collection<String> codeList, String errorCode, String objectName, String field) | |
| addCodes | back to summary |
|---|---|
| private void addCodes(Collection<String> codeList, String errorCode, String objectName, Iterable<String> fields) | |
| buildFieldList | back to summary |
|---|---|
| protected void buildFieldList(String field, List<String> fieldList) Add both keyed and non-keyed entries for the supplied | |
| getPrefix | back to summary |
|---|---|
| protected String getPrefix() Return the prefix to be applied to any code built by this resolver. Returns an empty String in case of no prefix. | |
| postProcessMessageCode | back to summary |
|---|---|
| protected String postProcessMessageCode(String code) Post-process the given message code, built by this resolver. The default implementation applies the specified prefix, if any. | |
| resolveMessageCodes | back to summary |
|---|---|
| public String[] resolveMessageCodes(String errorCode, String objectName) Implements org. Doc from org. Build message codes for the given error code and object name. Used for building the codes list of an ObjectError. | |
| resolveMessageCodes | back to summary |
|---|---|
| public String[] resolveMessageCodes(String errorCode, String objectName, String field, Class<?> fieldType) Implements org. Build the code list for the given code and field: an object/field-specific code, a field-specific code, a plain error code. Arrays, Lists and Maps are resolved both for specific elements and the whole collection. See the
| |
| setMessageCodeFormatter | back to summary |
|---|---|
| public void setMessageCodeFormatter(MessageCodeFormatter formatter) Specify the format for message codes built by this resolver. The default is
| |
| setPrefix | back to summary |
|---|---|
| public void setPrefix(String prefix) Specify a prefix to be applied to any code built by this resolver. Default is none. Specify, for example, "validation." to get error codes like "validation.typeMismatch.name". | |
MessageCodeFormatter, DefaultMessageCodesResolver#setMessageCodeFormatter(MessageCodeFormatter)
| Modifier and Type | Field and Description |
|---|---|
| public static final DefaultMessageCodesResolver. | POSTFIX_ERROR_CODE
Postfix the error code at the end of the generated message code. |
| public static final DefaultMessageCodesResolver. | PREFIX_ERROR_CODE
Prefix the error code at the beginning of the generated message code. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static String | toDelimitedString(String... elements)
Concatenate the given elements, delimiting each with
|
| public static DefaultMessageCodesResolver. | |
| public static DefaultMessageCodesResolver. |
| POSTFIX_ERROR_CODE | back to summary |
|---|---|
| public static final DefaultMessageCodesResolver. Postfix the error code at the end of the generated message code. e.g.:
| |
| PREFIX_ERROR_CODE | back to summary |
|---|---|
| public static final DefaultMessageCodesResolver. Prefix the error code at the beginning of the generated message code. e.g.:
| |
| Format | back to summary |
|---|---|
| private Format() | |
| toDelimitedString | back to summary |
|---|---|
| public static String toDelimitedString(String... elements) Concatenate the given elements, delimiting each with
| |
| valueOf | back to summary |
|---|---|
| public static DefaultMessageCodesResolver. | |
| values | back to summary |
|---|---|
| public static DefaultMessageCodesResolver. | |