Class TypeValidatorHelper

    • Field Detail

      • MESSAGE_PARAMETER_PATTERN

        protected static final java.util.regex.Pattern MESSAGE_PARAMETER_PATTERN
        Pattern to check whether validation message is a string resource id.
    • Constructor Detail

      • TypeValidatorHelper

        public TypeValidatorHelper()
    • Method Detail

      • buildErrorMessage

        protected void buildErrorMessage​(java.lang.String fieldName,
                                         @Nonnull
                                         javax.validation.ConstraintValidatorContext context,
                                         java.lang.Object... args)
        Creates custom error message.

        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

        Parameters:
        fieldName - name of field where the error occurred
        context - validation context
        args - optional message arguments
        Throws:
        java.lang.IllegalStateException - if the instance has not been initialized by Spring (see BasicBundleRuleValidator.initialize(Annotation) as an example of initialization)
        See Also:
        BundleTemplateDependsOnAncestorValidator, MessageFormat.format(String, Object...), I18NService
      • getCurrentLocale

        protected java.util.Locale getCurrentLocale()
      • getLocalizedString

        protected java.lang.String getLocalizedString​(java.lang.String key,
                                                      java.util.Locale locale)
      • getI18nService

        protected I18NService getI18nService()