Announcement Announcement Module
No announcement yet.
Tiles and Localisation Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tiles and Localisation

    Hi All,

    I am trying to get tiles working with localisation support.

    I have 3 files (tiles-def.xml,tiles-def_us.xml,tiles-def_de.xml) which represent the layouts for a particular locale.

    When a user logs in, he selects a locale, the select localed will be based off the particular locale tiles definition.

    E.g User selects the "us" locale, then the tiles-def_us.xml will be loaded

    Everytime I select the locale the default locale is always selected with the default tiles-definition..

    How do I set the locale so that my tiles configuration will load up the correct tiles definition.

    Heres is a snippet of my application context.xml

    	<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles.TilesConfigurer">
    	<property name="factoryClass">
    		<property name="definitions">
    	<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
    	    <property name="paramName"><value>siteLanguage</value></property>
        <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        	<property name="interceptors">
            	    <ref local="localeChangeInterceptor"/>
            <property name="mappings">
                    <prop key="*.sp">springappController</prop>
    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">

    Any help would be gratefully appreciated


  • #2
    Im pretty sure i can say that this would be very difficult to do with Tiles without a serious amount of reworking of Tiles.

    This is because Tiles doesn't have the support for seperating definition files for different purposes. All the tiles definitions are loaded into one factory class which is registered with the servlet context. The tiles tag libraries then use this one factory to locate the components to use. In other words, just one factory per servlet context is allowed.

    I can see a solution but first can i just check you need different layouts per locale? most people just change the content of the pages using <spring:message> and/or <fmt:message> in JSTL.

    The solution in tiles would be to have 3 different definition files all loaded with view names of (for examples) index, index_us, index_de (you can utilise Tiles extends to make these generic changes) and then code a new View Resolver which adds a _<locale> to the end of the view name or something like that.


    • #3
      Hi stueccles,

      Found the soloution

      A bit weird but it works,

      Tiles looks for the

      token "org.apache.struts.action.LOCALE" in the HTTP Session
      so I just set it in the session with a specific locale

      request.getSession&#40;true&#41;.setAttribute&#40;"org.apache.struts.action.LOCALE",new Locale&#40;"en","US"&#41;&#41;;

      Thanks for your suggestion though