Announcement Announcement Module
Collapse
No announcement yet.
Change locale not working - Please help me Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Change locale not working - Please help me

    Hi all,

    I'm trying to develop a multilanguage web application, I found the instruction to change the language at this link http://static.springsource.org/sprin...localeresolver and I have only add this code on my dispatcher-servlet :
    Code:
        
    <bean id="localeChangeInterceptor"
              class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
            <property name="paramName" value="siteLanguage"/>
        </bean>
    
        <bean id="localeResolver"
              class="org.springframework.web.servlet.i18n.CookieLocaleResolver"/>
    
        <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="interceptors">
                <list>
                    <ref bean="localeChangeInterceptor"/>
                </list>
            </property>
            <property name="mappings">
                <props>
                    <prop key="login.htm">indexController</prop>
    		<prop key="uploadfile.htm">fileUploadController</prop>
                    <prop key="successUpload.htm">successUploadController</prop>
                </props>
            </property>
        </bean>
    and I try to change the language with this link : index.htm?siteLanguage=en_EN
    but is not working.

    Please help me....

  • #2
    What about the MessageSource? I hope you have created that bean as well in your dispatcher-servlet.
    Also, you can refer to this link http://forum.springsource.org/showth...-messageSource

    Comment


    • #3
      I add this MessageSource :
      Code:
      <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
      		<property name="basename"><value>messages</value></property>										
      	</bean>
      but it doesn't work.

      I've try to add the tag in the falaserioaih's answer but I already have the tag viewResolver.
      This is my viewResolver:
      Code:
          <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
              <property name="requestContextAttribute" value="rc"/>
              <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
              <property name="prefix" value="/WEB-INF/jsp/"/>
              <property name="suffix" value=".jsp"/>
          </bean>
      and i can't replace it.



      PS : I'm sorry for my poor English...

      Comment


      • #4
        I have the same problem.
        The servlet xml succeed to load the message_en.properties
        But the language was not changed by changing the url language parameter
        I know that this work for some controllers (I have checked out localespring1 sample) but in my application the change of language do not take place.
        I use @RequestMapping(value="/out", method = RequestMethod.GET) can that course the problem?
        <?xml version="1.0" encoding="UTF-8"?>
        <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/p"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">



        <bean id="viewResolver"
        class="org.springframework.web.servlet.view.Intern alResourceViewResolver"
        prefix="/WEB-INF/jsp/" p:suffix=".jsp" />



        <bean id="themeSource"
        class="org.springframework.ui.context.support.Reso urceBundleThemeSource">
        <property name="basenamePrefix">
        <value>/WEB-INF/css/</value>
        </property>
        </bean>

        <bean id="messageSource"
        class="org.springframework.context.support.Reloada bleResourceBundleMessageSource">
        <property name="basename" value="classpath:message" />
        <property name="defaultEncoding" value="UTF-8" />
        </bean>

        <bean id="localeChangeInterceptor"
        class="org.springframework.web.servlet.i18n.Locale ChangeInterceptor">
        <property name="paramName" value="language" />
        </bean>

        <bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.Cookie LocaleResolver">
        <property name="defaultLocale" value="en" />
        </bean>


        <bean id="annotationMapper"
        class="org.springframework.web.servlet.mvc.annotat ion.DefaultAnnotationHandlerMapping">
        <property name="interceptors">
        <list>
        <ref bean="localeChangeInterceptor" />
        </list>
        </property>
        </bean>

        </beans>
        And the controller is here
        @Controller
        @RequestMapping("/filling")
        public class FillingController {
        protected static Logger logger = Logger.getLogger("controller");

        @RequestMapping(value="/out", method = RequestMethod.GET)
        public String getFillingOutPage(String language) {
        logger.debug("getFillingOutPage lang: "+ language);
        return "submitterDetails";
        }

        Comment


        • #5
          I solved the issue with a filter in my web.xml.

          You can see an example on appfuse : http://appfuse.org/display/APF/Home
          I've copied my filter from this sample application.

          Comment


          • #6
            How to use annotated controller in the urlmapping bean?

            The problem is not the filter in web.xml
            The problem is how to set the controller in the urlMapping bean defined in the servlet xml when the contoller is defined by annotation in the java class.
            <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
            <property name="urlMap">
            <map>
            <entry key="/testimony/pages/form/out"><ref bean="What to defined? name of bean?"/></entry>
            </map>
            </property>
            I have also tried this way of configuration
            <bean id="urlMapping"
            class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
            <property name="interceptors">
            <list>
            <ref bean="localeChangeInterceptor" />
            </list>
            </property>
            <property name="mappings">
            <props>
            <prop key="/testimony/pages/form/out">defaultController</prop>
            </props>
            </property>
            </bean>
            <bean id="defaultController" class="controller.FormController"/>
            Please, can some spring guru tell me how to define this controller in the servlet xml when I use annotation for the controller.

            @Controller
            @RequestMapping("/form")
            public class FormController {
            protected static Logger logger = Logger.getLogger("controller");

            @RequestMapping(value="/out", method = RequestMethod.GET)
            public String getFillingOutPage(String language) {
            logger.debug("getFillingOutPage lang: "+ language);
            The language parameter is passed but the Locale is not changed!!! why?
            Last edited by isys; Nov 16th, 2011, 05:45 AM.

            Comment


            • #7
              Concerning the controller config in the appliactionContext.xml it is defined like this
              [QUOTE]<?xml version="1.0" encoding="UTF-8"?>
              <beans xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:context="http://www.springframework.org/schema/context"
              xmlns:mvc="http://www.springframework.org/schema/mvc"
              xsi:schemaLocation="http://www.springframework.org/schema/beans
              http://www.springframework.org/schem...-beans-3.0.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schem...ontext-3.0.xsd
              http://www.springframework.org/schema/mvc
              http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
              <context:annotation-config />
              <context:component-scan base-package="controller" />
              So I still ask, how to define the annotated controller when the servlet xml do not know the bean name?
              Do the localeResolver only work for controllers that are defined in the servlet xml?
              Last edited by isys; Nov 16th, 2011, 05:43 AM.

              Comment

              Working...
              X