在Apache Tiles网站上与FreeMarker集成页面上:
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);
}
但我无法弄清楚我把这段代码放在哪里。你在这个代码上注册的正常位置是什么/我要扩展和覆盖哪个类?谢谢你的帮助。
答案 0 :(得分:1)
嗨,我刚想出来
这是我的项目herichy,我使用基于java的配置,webconfig就像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;
}
注意 tilesConfigurer.setTilesInitializer(new pringCompleteAutoloadTilesInitializer());
这是SpringCompleteAutoloadTilesInitializer
public class SpringCompleteAutoloadTilesInitializer extends CompleteAutoloadTilesInitializer
{
@Override
protected AbstractTilesContainerFactory createContainerFactory(ApplicationContext context)
{
return new SpringCompleteAutoloadTilesContainerFactory();
}
}
并且SpringCompleteAutoloadTilesContainerFactory是你想要代码的地方
您可以在git project
查看我的项目答案 1 :(得分:0)
此代码将进入您的TilesContainerFactory实现。
(通常扩展BasicTilesContainerFactory)。