wood burning stoves 2.0*
The moose likes Spring and the fly likes MVC 2.5 - How to get the MessageCodesResolver from within a Controller? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "MVC 2.5 - How to get the MessageCodesResolver from within a Controller?" Watch "MVC 2.5 - How to get the MessageCodesResolver from within a Controller?" New topic
Author

MVC 2.5 - How to get the MessageCodesResolver from within a Controller?

Nathan Russell
Ranch Hand

Joined: Aug 18, 2004
Posts: 75
Hi,
I'm trying to write an annotation based controller, and within one of its request methods I want to retrieve some text from within my messages resource bundle.
I can see from the Javadocs etc that some of the standard Spring controllers (BaseCommandController for example) have a method getMessageCodesResolver(), and from the returned implementation of MessageCodesResolver I can call one of the resolveMessageCodes methods ..... but I'm not extending any of the standard Spring controllers so I cant do this (can I?)

Below is my basic controller code and the method in question - any ideas as to how I can make the MessageCodesResolver available within my controller?


PS. The above is an over-simplified example of what I want to do. Clearly if all I wanted to do was the above I could write <spring:messages code="helpContent" /> within my JSP. In reality there are a number of help messages defined in the message file, and the controller will get the right one dependant on some other factors and add it to the model.

Cheers
Nathan
Nathan Russell
Ranch Hand

Joined: Aug 18, 2004
Posts: 75
OK, I've found a solution:

First off, I was referring to the wrong interface and class - what I was after was the MessageSource. By making my class implement MessageSourceAware and implementing the setMessageSource method, the MessageSource gets injected. From there its a simple task of calling its getMessage method when I need some message text

Then in my jsp I do this:





 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MVC 2.5 - How to get the MessageCodesResolver from within a Controller?
 
Similar Threads
Validation and binding in Spring3
JSF message in faces-config.xml itself
InternalResourceViewResolver failing JUnit test -- Spring Demo Source
@Controller annotation query
Dispatch Action Equivalent in Spring?