Abboq
Abboq

Reputation: 1101

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 with each request? If so, how can this be enabled?

Upvotes: 3

Views: 1205

Answers (3)

Marinos An
Marinos An

Reputation: 10826

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();

Upvotes: 0

farnoux
farnoux

Reputation: 66

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>

Upvotes: 3

Derrick
Derrick

Reputation: 2021

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. 

Upvotes: 1

Related Questions