In my app, I've made a switch for two languages (Eng\Rus) that must change the locale for the app. But, Spring LocaleResolver is not reacting to the request. This is a freemarker DropDown switch with "locale" var:
<ul class="nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" ><@spring.message "header.lang_switch" /><b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="?locale=en_US"><@spring.message "header.lang_switch_eng" /></a></li>
<li><a href="?locale=ru_RU"><@spring.message "header.lang_switch_ru" /></a></li>
</ul>
</li>
</ul>
This is my spring-servlet.xml config:
<!-- serving up static resources -->
<mvc:resources mapping="/static/**" location="/static/"/>
<!-- Configures Handler Interceptors -->
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
p:paramName="locale"/>
<!-- locale Resolver configuration-->
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<!--<property name="defaultLocale" value="en_US"/>-->
</bean>
<bean id="handlerMapping"
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
<property name="interceptors">
<list>
<ref bean="localeChangeInterceptor"/>
</list>
</property>
</bean>
<!-- Application Message Bundle -->
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="defaultEncoding" value="UTF-8"/>
<property name="fileEncodings" value="UTF-8"/>
<property name="cacheSeconds" value="0"/>
<property name="fallbackToSystemLocale" value="false"/>
<property name="useCodeAsDefaultMessage" value="true"/>
<property name="basenames">
<list>
<value>/WEB-INF/messages/messages</value>
<value>/WEB-INF/messages/labels</value>
<value>/WEB-INF/messages/include</value>
</list>
</property>
</bean>
And web.xml config:
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- ===================== i18n configurations =============================================== -->
<filter>
<filter-name>localizationFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>localizationFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
If I hard-code "defaultLocale" in "localeResolver" the page will load properly and all translation will be made properly. I clearly can see in fireBug that after switching locale, the locale changes in the page header. But, the content does not change on the page.
I have all needed configs that usualy needed:
<context:annotation-config/>
<context:component-scan base-package="serverMonitoring"/>
<mvc:annotation-driven />
Changes in LocalChangeInterseptor didn't give any changes:
<mvc:interceptors>
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
p:paramName="locale"/>
</mvc:interceptors>
One more thing; Does Spring-security have anything to do with Interceptor mechanism? Any help appreciated!!! Thank you.