您可以通过编写自己的DefinitionFactory
实现并在TilesConfigurer
.
public class CustomLocaleDefinitionsFactory extends LocaleDefinitionsFactory {
/** {@inheritDoc} */
@Override
public Definition getDefinition(String name, Request tilesContext) {
Definition retValue;
Locale locale = null;
retValue = definitionDao.getDefinition(name, locale);
if (retValue != null) {
retValue = new Definition(retValue);
String parentDefinitionName = retValue.getExtends();
while (parentDefinitionName != null) {
Definition parent = definitionDao.getDefinition(parentDefinitionName, locale);
if (parent == null) {
throw new NoSuchDefinitionException("Cannot find definition '" + parentDefinitionName
+ "' ancestor of '" + retValue.getName() + "'");
}
retValue.inherit(parent);
parentDefinitionName = parent.getExtends();
}
}
return retValue;
}
}
然后在注册上面定义的因子类,TilesConfigurer
以防这样使用spring。
TilesConfigurer configurer = new TilesConfigurer();
configurer.setDefinitions(new String[] { "/WEB-INF/layouts/tiles.xml",
"/WEB-INF/views/**/tiles.xml" });
configurer.setCheckRefresh(true);
configurer.setDefinitionsFactoryClass(CustomLocaleDefinitionsFactory.class);
return configurer;