LocaleResolver in Spring

12,071

You need to obtain the locale in this way:

Locale loc=RequestContextUtils.getLocale(request);
Share:
12,071
Jothi
Author by

Jothi

J2EE developer. Interested in Challanges.

Updated on June 04, 2022

Comments

  • Jothi
    Jothi about 2 years

    I am using session locale resolver for my application. I am showing the languages in dropdown. if the user selects on any of the language then repopulates all values from that language.

    <property name="interceptors">
        <list>
            <ref bean="localeChangeInterceptor" />
        </list>
    </property>
    
    <bean id="localeChangeInterceptor"
          class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="languageCode" />
    </bean>
    
    <bean id="localeResolver"
          class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />
    

    But its is not reading it from the session. Always it considers the defaultlanguage from browser setting. Please help on this.

  • KevinS
    KevinS over 13 years
    If the controller method is annotated with @RequestMapping, you can just add a Locale parameter to the method and Spring will automatically provide it for you. static.springsource.org/spring/docs/3.0.x/…
  • Ralph
    Ralph over 13 years
    @Kevin Stembridge: I would only make the statement, that it is a bed idea to obtain the locale direct from the session. -- And of course the parameter way is even much better thant what I have writen.