File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Nathan Russell
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic