How to register rendering attributes in Apache Tiles?

on the Integration with the FreeMarker page on the Apache Tiles website:

To access ".ftl" files as attributes, register FreeMarkerAttributeRenderer this way (only available in a servlet environment):

@Override
protected void registerAttributeRenderers(
        BasicRendererFactory rendererFactory, TilesApplicationContext applicationContext,
        TilesRequestContextFactory contextFactory,
        TilesContainer container, AttributeEvaluator evaluator) {
    super.registerAttributeRenderers(rendererFactory, applicationContext, contextFactory,
            container, evaluator);
    FreeMarkerAttributeRenderer freemarkerRenderer = new FreeMarkerAttributeRenderer();
    freemarkerRenderer.setApplicationContext(applicationContext);
    freemarkerRenderer.setEvaluator(evaluator);
    freemarkerRenderer.setRequestContextFactory(contextFactory);
    freemarkerRenderer.setParameter("TemplatePath", "/");
    freemarkerRenderer.setParameter("NoCache", "true");
    freemarkerRenderer.setParameter("ContentType", "text/html");
    freemarkerRenderer.setParameter("template_update_delay", "0");
    freemarkerRenderer.setParameter("default_encoding", "ISO-8859-1");
    freemarkerRenderer.setParameter("number_format", "0.##########");
    freemarkerRenderer.commit();
    rendererFactory.registerRenderer("freemarker", freemarkerRenderer);
}

      

But I cannot figure out where I am putting this code. What is the normal place where you register this code, in which class do I extend and overwrite? Thanks for your help.

+2


source to share


2 answers


Hi, I realized that now

enter image description here

this is my herichy project, i am using java config and webconfig as web.xml

    @Bean
public TilesConfigurer tilesConfigurer() {
    TilesConfigurer tilesConfigurer = new TilesConfigurer();
    tilesConfigurer.setDefinitions("/WEB-INF/views/tiles/tiles.xml");
    tilesConfigurer.setCheckRefresh(true);
    tilesConfigurer.setTilesInitializer(new pringCompleteAutoloadTilesInitializer());
    return tilesConfigurer;
}

      

notice tilesConfigurer.setTilesInitializer (new pringCompleteAutoloadTilesInitializer ());



this is SpringCompleteAutoloadTilesInitializer

public class SpringCompleteAutoloadTilesInitializer extends    CompleteAutoloadTilesInitializer
{
    @Override
    protected AbstractTilesContainerFactory   createContainerFactory(ApplicationContext context)
    {
        return new SpringCompleteAutoloadTilesContainerFactory();
    }
}

      

and that SpringCompleteAutoloadTilesContainerFactory is where you want to put your code

enter image description here

you can check my project here git project

+1


source


This code is included in your TilesContainerFactory implementation.



(which usually extends BasicTilesContainerFactory).

0


source







All Articles