views:

200

answers:

2

How can we resolve a message from properties file? Just like when we use

errors.reject ( "xyz.abc" );

in this case "xyz.abc" is resolved from the property file specified in messageResource ( servlet.xml )

+1  A: 

Just implement org.springframework.context.MessageSourceAware

rodrigoap
+6  A: 

Implement the MessageSourceAware interface in your class. Something like this should do the trick.

public class Foo implements MessageSourceAware {

    protected MessageSource messageSource;

    ...

    public void setMessageSource(MessageSource messageSource) {
        this.messageSource = messageSource;
    }

    ...

    public String bar(HttpServletRequest request, ...) {
        return messageSource.getMessage("xyz.abc", 
                new Object[] { "arg1", "arg2" }, 
                RequestContextUtils.getLocale(request));
    }
}
William Brendel
awesome, thanks :)
Rakesh Juyal
do we have to write any bean definition in the applicationContext.xml file ?
markitus82