views:

573

answers:

1

Hi im wondering would it be possible to create global interceptor and set locale there.

I have urlrewrite rules to rewrite /fr/* to /*?siteLang=fr

I see examples how to set locale based on parameter but they all are the same and require me to use url mappings. Is it possible to do it globally so that locale interceptor gets called on each request no matter what controller is it for?

<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
    <property name="paramName" value="siteLang"/>
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="interceptors">
        <list>
            <ref bean="localeChangeInterceptor"/>
        </list>
    </property>
    <property name="mappings">
        <value>
        /*=dispatchController
        </value>
    </property>
</bean>

There is no such thing as dispatchController in my xml so i cant use it but idea would be to intercept everything (in whatever way).

i would basically like to have urls with locale at the beginning of uri followed by the application bit like /fr/user/details /de/products/hifi etc

different controllers using the same convention of rewriting url and never using siteLang for controller specific reasons.

Thanks

+1  A: 
<mvc:interceptors>
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/>
</mvc:interceptors>
andrey maksimovich