Closed spring-projects-issues closed 19 years ago
Juergen Hoeller commented
Good idea! Default messages should be formatted as well, to allow for argument placeholders there - even if such messages will be plain text Strings most of the time.
Consequently, I've refined AbstractMessageSource to format passed-in default messages as well, resolving arguments when necessary. The used MessageFormats will be cached for efficiency.
Juergen
Xavier Leveque opened SPR-1008 and commented
When using method MessageSource.getMessage(String code, Object[] args, String defaultMessage, Locale locale), if the "code" can not be resolved in current message source or its parent(s), the "defaultMessage" is returned (or the "code" if "useCodeAsDefaultMessage" is set to true).
What if that default message (or code) contains parameters to be replaced by arguments.
It would be great if the "defaultMessage" (or "code") could be optionally formatted with the given arguments (if any) as the resolved message is.
This is something that should be done in the message source only if the code can't be resolved since obviously we don't want to pre-format the defaultMessage given as argument.
A new method could be added to the AbstractMessageSource class to activate/deactivate this behavior.
public void setFormatDefaultMessage(boolean formatDefaultMessage);
Another way would be to add a new argument to the method "getMessage()" that contains default arguments:
public String getMessage(String code, Object[] args, String defaultMessage, Object[] defaultArgs, Locale locale);
Affects: 1.2.1