jump to navigation

More on JSF and Spring Integration: MessageSources June 18, 2008

Posted by Phill in Frameworks.
Tags: , , ,

A couple of days ago I wanted to move my application messages file out of the classpath into WEB-INF for some reason which I can’t actually remember now. Anyway, Spring definitely supports loading message files from WEB-INF, but I don’t think JSF does (I think it loads resources from the classpath).

Plus, it makes sense to have all messages loaded from the one MessageSource – that way, if I add another messages file, the configuration will only need to be changed in one place.

After a bit of Googling, I managed to get it to work. If you want to have JSF using a Spring MessageSource, you will need to use the following class: MessageSourcePropertyResolver. Copy and paste that into your codebase somewhere. Then, edit your faces-config.xml file and add in the appropriate element:


Then, you can use the MessageSource in your JSF pages like this:#{messageSourceBeanName[‘message.key’]}

Tip: I don’t like typing out “messageSource” every time I want to use a message in a JSF page – I always used the shorter “msg” before. You can do this with Spring – just alias your MessageSource bean with the name “msg”. For example,

<alias name=”messageSource” alias=”msg” />



1. paul - November 17, 2010

I was looking for that for a long time 🙂 Thanks!

One question though: is there a way to make it works with parametrized string?

2. noel0402 - February 8, 2011

Thank you, you really save my project.
I successfully complete the implementation of load properties and reload change at runtime without reboot the web application.

Sorry comments are closed for this entry

%d bloggers like this: