Class MessageBuilder
java.lang.Object
org.springframework.binding.message.MessageBuilder
A convenient builder for building
MessageResolver
objects programmatically. Often used by model code such as
validation logic to conveniently record validation messages. Supports the production of message resolvers that
hard-code their message text, as well as message resolvers that retrieve their text from a message resource bundle
.
Usage example:
new MessageBuilder().error().source("field").code("mycode").arg(arg1).arg(arg2).defaultText("text").build();
- Author:
- Keith Donald, Jeremy Grelle
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionRecords that the message being built has a variable argument.Records that the message being built has variable arguments.build()
Builds the message that will be resolved.Records that the message being built should try and resolve its text using the code provided.Records that the message being built should try and resolve its text using the codes provided.defaultText
(String text) Records the fallback text of the message being built.error()
Records that the message being built is an error message.fatal()
Records that the message being built is a fatal message.info()
Records that the message being built is an informational message.resolvableArg
(Object arg) Records that the message being built has a variable argument, whose display value is alsoMessageSourceResolvable
.resolvableArgs
(Object... args) Records that the message being built has variable arguments, whose display values are alsoMessageSourceResolvable
instances.Records that the message being built is against the provided source.warning()
Records that the message being built is a warning message.
-
Constructor Details
-
MessageBuilder
public MessageBuilder()
-
-
Method Details
-
info
Records that the message being built is an informational message.- Returns:
- this, for fluent API usage
-
warning
Records that the message being built is a warning message.- Returns:
- this, for fluent API usage
-
error
Records that the message being built is an error message.- Returns:
- this, for fluent API usage
-
fatal
Records that the message being built is a fatal message.- Returns:
- this, for fluent API usage
-
source
Records that the message being built is against the provided source.- Parameters:
source
- the source to associate the message with- Returns:
- this, for fluent API usage
-
code
Records that the message being built should try and resolve its text using the code provided. Adds the code to the codes list. Successive calls to this method add additional codes. Codes are applied in the order they are added.- Parameters:
code
- the message code- Returns:
- this, for fluent API usage
-
codes
Records that the message being built should try and resolve its text using the codes provided. Adds the codes to the codes list. Successive calls to this method add additional codes. Codes are applied in the order they are added.- Parameters:
codes
- the message codes; if null, no changes will be made- Returns:
- this, for fluent API usage
-
arg
Records that the message being built has a variable argument. Adds the arg to the args list. Successive calls to this method add additional args. Args are applied in the order they are added.- Parameters:
arg
- the message argument value- Returns:
- this, for fluent API usage
-
args
Records that the message being built has variable arguments. Adds the args to the args list. Successive calls to this method add additional args. Args are applied in the order they are added.- Parameters:
args
- the message argument values, if null no changes will be made- Returns:
- this, for fluent API usage
-
resolvableArg
Records that the message being built has a variable argument, whose display value is alsoMessageSourceResolvable
. Adds the arg to the args list. Successive calls to this method add additional resolvable args. Args are applied in the order they are added.- Parameters:
arg
- the resolvable message argument- Returns:
- this, for fluent API usage
-
resolvableArgs
Records that the message being built has variable arguments, whose display values are alsoMessageSourceResolvable
instances. Adds the args to the args list. Successive calls to this method add additional resolvable args. Args are applied in the order they are added.- Parameters:
args
- the resolvable message arguments- Returns:
- this, for fluent API usage
-
defaultText
Records the fallback text of the message being built. If the message has no codes, this will always be used as the text. If the message has codes but none can be resolved, this will always be used as the text.- Parameters:
text
- the default text- Returns:
- this, for fluent API usage
-
build
Builds the message that will be resolved. Called after the end of recording builder instructions.- Returns:
- the built message resolver
-