PDA

View Full Version : Problem using ResourceBundleMessageSource



jazman
Jun 5th, 2007, 03:18 AM
Hi guys,

I am trying to implement this bean but cannot seem to get the output that I want. In my application context I have the following definition;



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


in my build path, with my class files, i have placed the messages.properties file and it contains the definition;



title=Ordering System


then in my jsp I have referenced this using the fmt tag;



<fmt:message key="title"/>


the prefix url is;



<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>


Im sure i've done everything right. I've used the spring mvc step by step as a skeleton guide. However instead of outputting the message "Ordering System" I simply get;



???title???


The only thing I could think of would be that the versions of jstl are in conflict with something. I am using a jsp 2.0 container, tomcat 5.5 and hence a jstl 1.1 definition. So everything there seems to okay. Is there anything else that I have overlooked or any other areas that could cause this issue?

Marten Deinum
Jun 5th, 2007, 04:06 AM
This question has been answered a few times, use the search. The most common mistake is that you access the jsp directly instead of through the DispatcherServlet (which will give you access to all the Spring beans).

jazman
Jun 5th, 2007, 05:14 AM
I have found the solution. Basically I was using an InternalResourceView instead of JstlView resolver. In other words I zigged;



<bean id="main" class="org.springframework.web.servlet.view.InternalResou rceView">
<property name="url">
<value>/WEB-INF/jsp/main.jsp</value>
</property>
</bean>


when i should have zagged;



<bean id="main" class="org.springframework.web.servlet.view.JstlView">
<property name="url">
<value>/WEB-INF/jsp/main.jsp</value>
</property>
</bean>


I only remember because I vaguely read something in the documentation;



When using the Java Standard Tag Library you must use a special view class, the JstlView, as JSTL needs some preparation before things such as the i18N features will work.

jazman
Jun 5th, 2007, 05:17 AM
This question has been answered a few times, use the search. The most common mistake is that you access the jsp directly instead of through the DispatcherServlet (which will give you access to all the Spring beans).

Thanks for your reply martin. Yes your right I should have done a search through the forums. One look and I would have found this

http://forum.springframework.org/showthread.php?t=35191&highlight=Problem+ResourceBundleMessageSource

Marten Deinum
Jun 5th, 2007, 05:38 AM
Doesn't matter, you where pointed in the right direction and solved your problem.