PDA

View Full Version : springMessage and ResourceBundle problem


mwaschkowski
Mar 20th, 2005, 09:50 AM
Hey Everyone!

First off, I want to say thanks to the people that wrote up the spring online docs and the MVC-step-by-step tutorial. They did a good job that didn't cost me anything, and deserve respect for that.

This morning I had some problems with being able to use the springMessage velocity tag with a MessageResource bundle. A couple of things to note:

1) On the page below, it shows the ResourceBundleMessageSource in the springapp/war/WEB-INF/springapp-servlet.xml:
http://www.springframework.org/docs/MVC-step-by-step/Spring-MVC-step-by-step-Part-2.html
2) One this page (13.4.5.3. form input generation macros), it shows using the message bundle like this: #springMessage($code)
http://www.springframework.org/docs/reference/view.html

For me, putting the ResourceBundleMessageSource in the servlet.xml file DID NOT WORK. Only after I carefully checked the logs did I find out that no ResourceBundleMessageSource was being loaded, after quite some time I might add :( Then, it still didn't work on the page. I had to use the following format:
#springMessage("userAdmin.firstName")

I like Spring alot. It gives a lot. But, docs are still very limited, and now that I've wasted a couple of hours trying to configure it, and its frustrating.

Suggestions, meant in the most constructive manner:
1) Put the ResourceBundleMessageSource in the applicationContext.xml
2) Update the velocity page are take out the $ except where required for velocity, confusing otherwise.

Best regards,

Mark

heiho1
Mar 21st, 2005, 03:51 PM
For me, putting the ResourceBundleMessageSource in the servlet.xml file DID NOT WORK. Only after I carefully checked the logs did I find out that no ResourceBundleMessageSource was being loaded, after quite some time I might add :( Then, it still didn't work on the page. I had to use the following format:
#springMessage("userAdmin.firstName")

I like Spring alot. It gives a lot. But, docs are still very limited, and now that I've wasted a couple of hours trying to configure it, and its frustrating.

Suggestions, meant in the most constructive manner:
1) Put the ResourceBundleMessageSource in the applicationContext.xml
2) Update the velocity page are take out the $ except where required for velocity, confusing otherwise.


I also found this confusing. What you have to do is look at

org.springframework.web.servlet.view.velocity.Velo cityViewResolver#setRequestContextAttribute(String )

method. You can configure this to give you access to the

org.springframework.web.servlet.support.RequestCon text

instance which is configured by spring using the messagesource configuration you have described above. For me, I use the following:


<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.Velo cityViewResolver">
<property name="requestContextAttribute">
<value>rc</value>
</property>
<property name="exposeSpringMacroHelpers">
<value>true</value>
</property>
<property name="suffix"><value>.vm</value></property>
</bean>


Then, you can call ${rc.getMessage("message.key")} ... it is fairly obtuse to configure without reading the Javadocs...

nidhi
Sep 10th, 2007, 02:23 AM
Hi,

I am using #springMessage in velocity template for getting message values from message resource bundle.

in xxx-sevlet.xml I configured like this.

<bean id="messageSource" class="org.springframework.context.support.ResourceBundle MessageSource">
<property name="basename">
<value>messages</value>
</property>
</bean>

and i have messages.properties in classpath with 2 other language properties.

default language

title = TITLE
heading=HEADING
greeting=GREETING

norwegian language

title = TITLE_NO
heading=HEADING_NO
greeting=GREETING_NO



bt the problem is its displaying for default language only. If i change the language settings in browser its not affecting the message keys. So i alwys gets message for #springMessage("title") as TITLE independant of language.


i tried the bean configuration in applicationContext.xml also

Please help.


thanks in adavance
Nidhi