Spring MVC equivalent to getText () from Struts for I18N

In Struts2, the ActionSupportclass has a method getText(String key, ...)that returns a localized message from the i18n resource set. Is Spring MVC the equivalent of this?

I know there is a tag <spring:message>, but that is not what I need. I need to get a localized message inside a controller class, not a JSP.

+3
source share
1 answer

To do this, you can use the source SpringMessage:

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 details:

http://docs.spring.io/spring/docs/3.0.0.RC2/reference/html/ch03s13.html

+3
source

All Articles