• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:





 
If a regular clown is funny, then a larger clown would be funnier. Math. Verified by this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic