we are using Spring MessageSource to build error messages in our app.
We populate our error messages like this
dobInvalid = The DOB supplied {0} is invalid
We want to use named parameters so we can do
dobInvalid = The DOB supplied {dob} is invalid
Looking in the Api docs for getMessage it appears to suggest you can do this http://static.springsource.org/spring/docs/1.2.x/api/org/springframework/context/MessageSource.html
args - Array of arguments that will be filled in for params within the message (params look like "{0}", "{1,date}", "{2,time}" within a message), or null if none.
Obviously we can write our own but was wondering if spring can do it and if anyone can provide an example or using named parameters rather positional parameters.
Cheers Mark
AIUI, Spring MessageSource works with JDK MessageFormat, so there is no such a named parameter. {1,date}
is an example, where "date" refers to formatType, no to an arbitrary named parameter.
The general form of a parameter is:
{ ArgumentIndex , FormatType , FormatStyle }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With