Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring LocaleResolver not reacting to locale
    text
    copied!<p>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:</p> <pre><code> &lt;ul class="nav"&gt; &lt;li class="dropdown"&gt; &lt;a href="#" class="dropdown-toggle" data-toggle="dropdown" &gt;&lt;@spring.message "header.lang_switch" /&gt;&lt;b class="caret"&gt;&lt;/b&gt;&lt;/a&gt; &lt;ul class="dropdown-menu"&gt; &lt;li&gt;&lt;a href="?locale=en_US"&gt;&lt;@spring.message "header.lang_switch_eng" /&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="?locale=ru_RU"&gt;&lt;@spring.message "header.lang_switch_ru" /&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>This is my spring-servlet.xml config:</p> <pre><code>&lt;!-- serving up static resources --&gt; &lt;mvc:resources mapping="/static/**" location="/static/"/&gt; &lt;!-- Configures Handler Interceptors --&gt; &lt;bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="locale"/&gt; &lt;!-- locale Resolver configuration--&gt; &lt;bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"&gt; &lt;!--&lt;property name="defaultLocale" value="en_US"/&gt;--&gt; &lt;/bean&gt; &lt;bean id="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"&gt; &lt;property name="interceptors"&gt; &lt;list&gt; &lt;ref bean="localeChangeInterceptor"/&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- Application Message Bundle --&gt; &lt;bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt; &lt;property name="defaultEncoding" value="UTF-8"/&gt; &lt;property name="fileEncodings" value="UTF-8"/&gt; &lt;property name="cacheSeconds" value="0"/&gt; &lt;property name="fallbackToSystemLocale" value="false"/&gt; &lt;property name="useCodeAsDefaultMessage" value="true"/&gt; &lt;property name="basenames"&gt; &lt;list&gt; &lt;value&gt;/WEB-INF/messages/messages&lt;/value&gt; &lt;value&gt;/WEB-INF/messages/labels&lt;/value&gt; &lt;value&gt;/WEB-INF/messages/include&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>And web.xml config:</p> <pre><code>&lt;filter&gt; &lt;filter-name&gt;characterEncodingFilter&lt;/filter-name&gt; &lt;filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter&lt;/filter-class&gt; &lt;init-param&gt; &lt;param-name&gt;encoding&lt;/param-name&gt; &lt;param-value&gt;UTF-8&lt;/param-value&gt; &lt;/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;forceEncoding&lt;/param-name&gt; &lt;param-value&gt;true&lt;/param-value&gt; &lt;/init-param&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;characterEncodingFilter&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; &lt;!-- ===================== i18n configurations =============================================== --&gt; &lt;filter&gt; &lt;filter-name&gt;localizationFilter&lt;/filter-name&gt; &lt;filter-class&gt;org.springframework.web.filter.RequestContextFilter&lt;/filter-class&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;localizationFilter&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; </code></pre> <p>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. </p> <p>I have all needed configs that usualy needed:</p> <pre><code>&lt;context:annotation-config/&gt; &lt;context:component-scan base-package="serverMonitoring"/&gt; &lt;mvc:annotation-driven /&gt; </code></pre> <p>Changes in LocalChangeInterseptor didn't give any changes:</p> <pre><code>&lt;mvc:interceptors&gt; &lt;bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="locale"/&gt; &lt;/mvc:interceptors&gt; </code></pre> <p>One more thing; Does Spring-security have anything to do with Interceptor mechanism? Any help appreciated!!! Thank you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload