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.
posted 8 years ago
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 yam what I yam and that's all that I yam - the great philosopher Popeye. Tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java