Top Description Inners Fields Constructors Methods
org.springframework.web.util

public abstract Class BindErrorUtils

extends Object
Class Inheritance
Imports
java.util.LinkedHashMap, .List, .Locale, .Map, java.util.stream.Collectors, org.springframework.context.MessageSource, .MessageSourceResolvable, org.springframework.context.support.StaticMessageSource, org.springframework.util.StringUtils, org.springframework.validation.FieldError

Utility methods to resolve a list of MessageSourceResolvables, and optionally join them.
Author
Rossen Stoyanchev
Since
6.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
BindErrorUtils.MethodArgumentErrorMessageSource

MessageSource for default error formatting.

Field Summary

Modifier and TypeField and Description
private static final MessageSource

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static <E extends MessageSourceResolvable> Map<E, String>
resolve(List<E> errors)

Shortcut for resolve(List, MessageSource, Locale) with an empty MessageSource that simply formats the default message, or first error code, also prepending the field name for field errors.

public static <E extends MessageSourceResolvable> Map<E, String>

Returns:

map with resolved errors as values, in the order of the input list
resolve
(List<E>
the errors to resolve
errors
,
MessageSource
the MessageSource to resolve with
messageSource
,
Locale
the locale to resolve with an empty MessageSource
locale
)

Resolve all errors through the given MessageSource.

public static String
resolveAndJoin(List<? extends MessageSourceResolvable> errors)

Shortcut for resolveAndJoin(List, MessageSource, Locale) with an empty MessageSource that simply formats the default message, or first error code, also prepending the field name for field errors.

public static String
resolveAndJoin(List<? extends MessageSourceResolvable> errors, MessageSource messageSource, Locale locale)

Shortcut for resolveAndJoin(CharSequence, CharSequence, CharSequence, List, MessageSource, Locale) with ", and " as delimiter, and an empty prefix and suffix.

public static String

Returns:

the resolved errors formatted as a string
resolveAndJoin
(CharSequence
the delimiter to use between each error
delimiter
,
CharSequence
characters to insert at the beginning
prefix
,
CharSequence
characters to insert at the end
suffix
,
List<? extends MessageSourceResolvable>
the errors to resolve and join
errors
,
MessageSource
the MessageSource to resolve with
messageSource
,
Locale
the locale to resolve with
locale
)

Resolve all errors through the given MessageSource and join them.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultMessageSourceback to summary
private static final MessageSource defaultMessageSource

Constructor Detail

BindErrorUtilsback to summary
public BindErrorUtils()

Method Detail

resolveback to summary
public static <E extends MessageSourceResolvable> Map<E, String> resolve(List<E> errors)

Shortcut for resolve(List, MessageSource, Locale) with an empty MessageSource that simply formats the default message, or first error code, also prepending the field name for field errors.

resolveback to summary
public static <E extends MessageSourceResolvable> Map<E, String> resolve(List<E> errors, MessageSource messageSource, Locale locale)

Resolve all errors through the given MessageSource.

Parameters
errors:List<E>

the errors to resolve

messageSource:MessageSource

the MessageSource to resolve with

locale:Locale

the locale to resolve with an empty MessageSource

Returns:Map<E, String>

map with resolved errors as values, in the order of the input list

resolveAndJoinback to summary
public static String resolveAndJoin(List<? extends MessageSourceResolvable> errors)

Shortcut for resolveAndJoin(List, MessageSource, Locale) with an empty MessageSource that simply formats the default message, or first error code, also prepending the field name for field errors.

resolveAndJoinback to summary
public static String resolveAndJoin(List<? extends MessageSourceResolvable> errors, MessageSource messageSource, Locale locale)

Shortcut for resolveAndJoin(CharSequence, CharSequence, CharSequence, List, MessageSource, Locale) with ", and " as delimiter, and an empty prefix and suffix.

resolveAndJoinback to summary
public static String resolveAndJoin(CharSequence delimiter, CharSequence prefix, CharSequence suffix, List<? extends MessageSourceResolvable> errors, MessageSource messageSource, Locale locale)

Resolve all errors through the given MessageSource and join them.

Parameters
delimiter:CharSequence

the delimiter to use between each error

prefix:CharSequence

characters to insert at the beginning

suffix:CharSequence

characters to insert at the end

errors:List<? extends MessageSourceResolvable>

the errors to resolve and join

messageSource:MessageSource

the MessageSource to resolve with

locale:Locale

the locale to resolve with

Returns:String

the resolved errors formatted as a string

org.springframework.web.util back to summary

private Class BindErrorUtils.MethodArgumentErrorMessageSource

extends StaticMessageSource
Class Inheritance

MessageSource for default error formatting.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected String
getDefaultMessage(MessageSourceResolvable
the value object to resolve a default message for
resolvable
,
Locale
the current locale
locale
)

Overrides org.springframework.context.support.AbstractMessageSource.getDefaultMessage.

Get a default message for the given MessageSourceResolvable.

Inherited from org.springframework.context.support.StaticMessageSource:
addMessageaddMessagesresolveCoderesolveCodeWithoutArgumentstoString

Constructor Detail

MethodArgumentErrorMessageSourceback to summary
pack-priv MethodArgumentErrorMessageSource()

Method Detail

getDefaultMessageback to summary
protected String getDefaultMessage(MessageSourceResolvable resolvable, Locale locale)

Overrides org.springframework.context.support.AbstractMessageSource.getDefaultMessage.

Doc from org.springframework.context.support.AbstractMessageSource.getDefaultMessage.

Get a default message for the given MessageSourceResolvable.

This implementation fully renders the default message if available, or just returns the plain default message String if the primary message code is being used as a default message.

Parameters
resolvable:MessageSourceResolvable

the value object to resolve a default message for

locale:Locale

the current locale

Returns:String

the default message, or null if none

Annotations
@Override