In Struts2 ActionSupport class has getText(String key, ...) method that returns a localized message from i18n resource bundle. Is there any Spring MVC equivalent of this?
I know that there is <spring:message> tag, but it is not what I need. I need to retrieve localized message inside controller class, not on JSP.
You can use SpringMessage source for this:
public class Example {
private MessageSource messages;
public void setMessages(MessageSource messages) {
this.messages = messages;
}
public void execute() {
String message = this.messages.getMessage("argument.required",
new Object [] {"userDao"}, "Required", null);
System.out.println(message);
}
}
See here for more info:
http://docs.spring.io/spring/docs/3.0.0.RC2/reference/html/ch03s13.html
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