public class TypeValidatorHelper extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static Pattern |
MESSAGE_PARAMETER_PATTERN
Pattern to check whether validation message is a string resource id.
|
| Constructor and Description |
|---|
TypeValidatorHelper() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
buildErrorMessage(String fieldName,
ConstraintValidatorContext context,
Object... args)
Creates custom error message.
|
protected Locale |
getCurrentLocale() |
protected I18NService |
getI18nService() |
protected String |
getLocalizedString(String key,
Locale locale) |
protected ResourceBundleProvider |
getResourceBundleProvider() |
protected static final Pattern MESSAGE_PARAMETER_PATTERN
protected void buildErrorMessage(String fieldName, ConstraintValidatorContext context, Object... args)
Message template is taken from validation context.
In general it is the one specified in C.message field.
Strings {string.resource.id} treated as string key of localized string resource.
Current add locale is used to resolve value.
To have such string as it is, double the surrounding curly brackets:
{{not.a.resource{0}}}
will be show as
{not.a.resource<value_of_first_arg>}
The resulting string is then passed to MessageFormat.format(String, Object...) along with args
only if any args provided.
Please pay attention to syntax inconsistency between parametrized and non-parametrized lines:
It''s a parametrized line with arg ''{0}''
but
It'a a non-parametrized line
fieldName - name of field where the error occurredcontext - validation contextargs - optional message argumentsIllegalStateException - if the instance has not been initialized by Spring
(see BasicBundleRuleValidator.initialize(Annotation) as an example of initialization)BundleTemplateDependsOnAncestorValidator,
MessageFormat.format(String, Object...),
I18NServiceprotected Locale getCurrentLocale()
protected I18NService getI18nService()
protected ResourceBundleProvider getResourceBundleProvider()
Copyright © 2017 SAP SE. All Rights Reserved.