Enable Tiles devMode like Struts' devMode to reload tiles.xml with each request
Does Apache Tiles have a devMove like Struts that would reload the tiles.xml file 开发者_JS百科with each request? If so, how can this be enabled?
Here is another working configuration that uses Listener instead of Filter. (since Tiles 2.1.2)
In web.xml:
<context-param>
<param-name>org.apache.tiles.definition.dao.LocaleUrlDefinitionDAO.CHECK_REFRESH</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>org.apache.tiles.web.startup.TilesListener</listener-class>
</listener>
I've used tiles, but have never tried to dynamically reload it.
However, this page : http://tiles.apache.org/tutorial/configuration.html
says:
Load the Tiles filter. It is useful if your definition files can be changed and you periodically need to reload them.
The following has worked for me using tiles 2.2.2 inside servlet container.
....
import org.apache.tiles.definition.DefinitionsFactory;
import org.apache.tiles.definition.UnresolvingLocaleDefinitionsFactory;
import org.apache.tiles.definition.dao.ResolvingLocaleUrlDefinitionDAO;
import org.apache.tiles.impl.BasicTilesContainer;
import org.apache.tiles.servlet.context.ServletUtil;
//When using SimpleTilesListener => BasicTilesContainer is returned
//When using StrutsTilesListener => CachingTilesContainer is returned which extends BasicTilesContainer
BasicTilesContainer tilesCont = (BasicTilesContainer) ServletUtil.getContainer(ServletActionContext.getServletContext());
DefinitionsFactory defFact = tilesCont.getDefinitionsFactory();
Field field= UnresolvingLocaleDefinitionsFactory.class.getDeclaredField("definitionDao");
field.setAccessible(true);
ResolvingLocaleUrlDefinitionDAO rludDAO = (ResolvingLocaleUrlDefinitionDAO)field.get(defFact);
rludDAO.refresh();
精彩评论