像 Struts 一样启用 Tiles devMode devMode 在每次请求时重新加载tiles.xml

发布于 2024-08-24 21:27:39 字数 83 浏览 9 评论 0原文

Apache Tiles 是否有像 Struts 一样的 devMove,可以根据每个请求重新加载tiles.xml 文件?如果是这样,如何启用此功能?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟火散人牵绊 2024-08-31 21:27:39

这是另一个使用 Listener 而不是 Filter 的工作配置。
(自 Tiles 2.1.2 起)

在 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>

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>
枯寂 2024-08-31 21:27:39

我使用过图块,但从未尝试过动态重新加载它。

但是,此页面: http://tiles.apache.org/tutorial/configuration.html

说:

    Load the Tiles filter. It is useful if your definition files can be changed and you periodically need to reload them. 

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. 
梦明 2024-08-31 21:27:39

以下内容对我在servlet容器内使用tiles 2.2.2有用。

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

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文