0

We are trying to implement internationalization using Spring ResourceBundleMessageSource and FMT. But when we use it in the JSP, pages are displaying value as ???message.key???. Can you please help us in resolving this behavior? Really appreciate your answers.

Below are the configuration:

spring-servlet.xml entry

<bean id="messageSource"   
class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename">
        <value>WEB-INF/messages/msgs</value>            
    </property> </bean>

<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
    <property name="paramName">
        <value>locale</value>
    </property>  </bean>

 <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"/>


<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
    <property name="interceptors">
        <list>             
            <ref bean="localeChangeInterceptor" />                          
        </list>
    </property> 
</bean>

IN the JSP we have added the imported

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

<fmt:message key="message.key"/>

Also in the war created we have the msgs.properties file under WEB-INF/messages folder.

Really appreciate help in identifying the mistake we are making. Thank you.

Manjunath
  • 172
  • 1
  • 2
  • 18

3 Answers3

0

I am using the same as you and I am able to retrieve the messages from the properties file with fmt:message. Can you try to change the resource bundle for this:

<bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basenames">
            <list>
                <value>classpath:messages</value>
            </list>
        </property>
        <property name="defaultEncoding" value="UTF-8" />
        <property name="fallbackToSystemLocale" value="false"></property>
    </bean>

The properties are stored in src/main/resources.

Hope it helps.

Gerard Ribas
  • 717
  • 1
  • 9
  • 17
  • Thanks for your reply. But still not resolving the issue. We have multiple spring contexts with one web app contexts. We are defining this messageSource as part of web application context. is it right? do we have dependency on the page encoding type in the JSPs? We are using 3.1.2 release version of spring. Let me know your thoughts. – Manjunath Oct 16 '13 at 18:02
  • Will it have any dependencies on the version of JSTL ? We are using the one provided by JBoss 7.1.1. – Manjunath Oct 17 '13 at 03:20
0

Using FMT taglibraries we could not solve the issue. I believe it has got some thing to do with the jstl jar and taglibs which we are using with JBoss 7.1.1 server.

We started using spring tlds for displaying the messages. All is working fine now. Thanks for the help.

Manjunath
  • 172
  • 1
  • 2
  • 18
0

Use /WEB-INF/messages/msgs instead of WEB-INF/messages/msgs

Simply, add '/' at the beginning of path.