You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tiles.apache.org by Brett Ryan <br...@gmail.com> on 2016/08/23 12:44:42 UTC

How does one use localised tiles definitions with Spring?

Hey all, trying to determine how to use tiles definitions within a spring mvc application using a spring cookie locale resolver.

My spring resource bundles are being changed properly as by my <spring:message/> tags, and ${pageContext.response.locale} reports the correct locale, however my tiles definitions aren't being picked up. I wish to have a different layout for some locales.

My TilesConfigurer is as follows:

    @Bean
    public TilesConfigurer tilesConfigurer() {
        TilesConfigurer res = new TilesConfigurer();
        res.setTilesInitializer(new SpringCompleteAutoloadTilesInitializer());
        res.setDefinitions("/WEB-INF/**/tiles*.xml");
        return res;
    }
 
SpringCompleteAutoloadTilesInitializer is a custom initialiser that looks as follows:

public class SpringCompleteAutoloadTilesContainerFactory extends CompleteAutoloadTilesContainerFactory {

    @Override
    protected PreparerFactory createPreparerFactory(ApplicationContext context) {
        return new SpringBeanPreparerFactory();
    }

    @Override
    protected LocaleResolver createLocaleResolver(ApplicationContext applicationContext) {
        return new SpringLocaleResolver();
    }

}

I verified that the locale is working and gets returned correctly on each request by creating a wrapper class, so the locale is getting returned.

Now for my definitions I have

tiles.xml:

  <definition name="home" extends="default.layout">
    <put-list-attribute name="body" inherit="true" cascade="true">
      <add-attribute value="/WEB-INF/views/home.jsp" />
    </put-list-attribute>
  </definition>

and tiles_fr.xml

  <definition name="home" extends="default.layout">
    <put-list-attribute name="body" inherit="true" cascade="true">
      <add-attribute value="/WEB-INF/views/home_fr.jsp" />
    </put-list-attribute>
  </definition>

Everything runs fine, yet for the "home" view, the home_fr.jsp is not being rendered, home.jsp gets rendered.




Re: How does one use localised tiles definitions with Spring?

Posted by Brett Ryan <br...@gmail.com>.
Oh god, I'm a wank!

I had my tiles_fr.xml spelt tiiles_fr.xml.

I knew this worked in prior projects.

So sorry guys, completely forget this one.

> On 23 Aug 2016, at 22:44, Brett Ryan <br...@gmail.com> wrote:
> 
> Hey all, trying to determine how to use tiles definitions within a spring mvc application using a spring cookie locale resolver.
> 
> My spring resource bundles are being changed properly as by my <spring:message/> tags, and ${pageContext.response.locale} reports the correct locale, however my tiles definitions aren't being picked up. I wish to have a different layout for some locales.
> 
> My TilesConfigurer is as follows:
> 
>    @Bean
>    public TilesConfigurer tilesConfigurer() {
>        TilesConfigurer res = new TilesConfigurer();
>        res.setTilesInitializer(new SpringCompleteAutoloadTilesInitializer());
>        res.setDefinitions("/WEB-INF/**/tiles*.xml");
>        return res;
>    }
> 
> SpringCompleteAutoloadTilesInitializer is a custom initialiser that looks as follows:
> 
> public class SpringCompleteAutoloadTilesContainerFactory extends CompleteAutoloadTilesContainerFactory {
> 
>    @Override
>    protected PreparerFactory createPreparerFactory(ApplicationContext context) {
>        return new SpringBeanPreparerFactory();
>    }
> 
>    @Override
>    protected LocaleResolver createLocaleResolver(ApplicationContext applicationContext) {
>        return new SpringLocaleResolver();
>    }
> 
> }
> 
> I verified that the locale is working and gets returned correctly on each request by creating a wrapper class, so the locale is getting returned.
> 
> Now for my definitions I have
> 
> tiles.xml:
> 
>  <definition name="home" extends="default.layout">
>    <put-list-attribute name="body" inherit="true" cascade="true">
>      <add-attribute value="/WEB-INF/views/home.jsp" />
>    </put-list-attribute>
>  </definition>
> 
> and tiles_fr.xml
> 
>  <definition name="home" extends="default.layout">
>    <put-list-attribute name="body" inherit="true" cascade="true">
>      <add-attribute value="/WEB-INF/views/home_fr.jsp" />
>    </put-list-attribute>
>  </definition>
> 
> Everything runs fine, yet for the "home" view, the home_fr.jsp is not being rendered, home.jsp gets rendered.
> 
> 
>