Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC equivalent of getText() from Struts for I18N

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.

like image 835
dzielins42 Avatar asked Jan 29 '26 08:01

dzielins42


1 Answers

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

like image 183
hutchonoid Avatar answered Jan 30 '26 20:01

hutchonoid