Announcement Announcement Module
Collapse
No announcement yet.
LocaleChangeInterceptor configuration problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • LocaleChangeInterceptor configuration problem

    Hello everyone,

    I'm building an application with the initial configuration based on the booking-faces.

    I managed to configure the resource bundle correctly. The problem is: no matter what I do the LocaleChangeInterceptor doesn't intercept my request, or at least my debugger doesn't show it, and indeed the locale doesn't change.

    This the relevant bit of my configuration:

    ../resources/messages.properties
    ../resources/messages_pt.properties

    webmvc-config.xml:
    Code:
    <bean id="msgSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"	p:basename="classpath:messages"/>
    <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />
    faces-config.xml: (where MySpringBeanFacesELResolver is exactly as ivats.)
    Code:
    <application>
        <el-resolver>pt.m24.portal.utils.MySpringBeanFacesELResolver</el-resolver>
        <locale-config>
    	  <default-locale>en</default-locale>
    	  <supported-locale>pt</supported-locale>
        </locale-config>
        <resource-bundle>
    	  <base-name>messages</base-name>
    	  <var>msg</var>
        </resource-bundle>
    </application>

    main.xhtml:
    (the bit of the file where I want to change locale)

    Code:
    <h:outputLink id="enLocaleUrl" value="/app/welcome" >
         <f:param name="locale" value="" />
         <h:outputLabel value="#{msgSource.locale_english}"/>
    </h:outputLink>
    <h:outputLink id="ptLocaleUrl" value="/app/welcome" >
          <f:param name="locale" value="pt" />
          <h:outputLabel value="#{msgSource.locale_portuguese}"/>
    </h:outputLink>
    Can anyone please point me in the right direction.
    Thank you in advance.

  • #2
    Just declaring the LocaleChangeInterceptor class as a Spring bean won't do. You need to tell Spring that this bean IS an interceptor; for this use the mvc:interceptors command contained in the mvc namespace:

    Code:
      <mvc:interceptors>
        <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
      </mvc:interceptors>

    Comment


    • #3
      Thank you for your reply Enrico, I just realized my post is incomplete, I already tried to use:

      Code:
      <bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
          <property name="interceptors">
               <list>
                    <ref bean="localeChangeInterceptor" />
               </list>
          </property>
      </bean>
      and

      Code:
      <mvc:interceptors>
          	<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
      </mvc:interceptors>
      without success, my request still isn't intercepted. Yesterday I went back on the booking-faces original configuration and tried to do it from the beginning
      and no luck still.

      Comment


      • #4
        does your locale change request's query string include a "locale" parameter?

        http://myserver:myport/mypage?locale=it&otherparameters...

        If not, then it's normal that the interceptor will do nothing. If you pass the locale parameter with another name, say "lang", you have to configure the property "paramName" in the bean definition:

        Code:
          <mvc:interceptors>
            <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
                <property name="paramName" value="lang"/>
            </bean>
          </mvc:interceptors>

        Comment


        • #5
          Yes, the query produced by:

          Code:
          <h:outputLink id="enLocaleUrl" value="/app/welcome" >
               <f:param name="locale" value="" />
               <h:outputLabel value="#{msgSource.locale_english}"/>
          </h:outputLink>
          <h:outputLink id="ptLocaleUrl" value="/app/welcome" >
                <f:param name="locale" value="pt" />
                <h:outputLabel value="#{msgSource.locale_portuguese}"/>
          </h:outputLink>
          ends with ?locale=pt or ?locale=en

          I already tried to enforce the paramName with:
          Code:
          <mvc:interceptors>
                  <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" >
                      <property name="paramName" value="locale" />
                  </bean>
          </mvc:interceptors>
          and still no result, I don't understand this behavior.

          Comment


          • #6
            I've found the problem, because the booking-faces uses FlowHandlerMapping the interceptor must be explicitly declared in it, something like this:

            Code:
            <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
                    <property name="flowRegistry" ref="flowRegistry" />
                    <property name="defaultHandler">
                        <!-- If no flow match, map path to a view to render; e.g. the "/intro" path would map to the view named "intro" -->
                        <bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
                    </property>
                    <property name="interceptors">
                        <list>
                          <ref bean="localeChangeInterceptor" />
                        </list>
                      </property>
            </bean>
            Thank you for your help.

            Comment


            • #7
              ha-ha...you never mentioned you were using Spring Web Flow (though the fact that it was a faces application should have prompted me to think of it, since Spring web mvc and faces don't go very well together unless through Web Flow), or I would have pointed you to the right solution sooner.

              Well, hopefully this thread will also help other people with the same problem.

              Best regards,

              Enrico

              Comment

              Working...
              X