JSF和自动重载xhtml文件

时间:2011-09-22 09:18:49

标签: java jsf facelets mojarra jrebel

我在使用JRebel,Spring,JSF Mojarra 2.0.3和WebLogic 10.3热重新加载XHTML文件方面遇到了一些问题。

JRebel成功地在/ WebContent下重新加载常规Java类和js / css文件,但不重新加载JSF的.xhtml文件。需要完整的重新发布才能在服务器上更新xhtml文件。

通过反复试验,我终于通过向web.xml添加一些facelets参数并按照in this blog post所述创建自定义ResourceResolver来实现它。

然而,我想知道为什么这有效,更具体地说:

  • 为什么需要自定义ResourceResolver?
  • 是不是应该通过监视xhtml文件所在的/ WebContent来处理这个问题?
  • 我猜测它与Facelets / JSF通过FacesServlet将xhtml编译为servlets(?)有什么关系,JRebel无法检测到它?

2 个答案:

答案 0 :(得分:42)

JRebel处理/ WebContent文件夹更改。

问题是Facelets会进行缓存而不会重新读取已更改的文件。要强制重新读取,请在web.xml中指定以下参数。

JSF 2 (Facelets 2.x):

<!-- Time in seconds that facelets should be checked for changes since last request. A value of -1 disables refresh checking. -->
<context-param>
    <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
    <param-value>0</param-value>
</context-param>

<!-- Set the project stage to "Development", "UnitTest", "SystemTest", or "Production". -->
<!-- An optional parameter that makes troubleshooting errors much easier. -->
<!-- You should remove this context parameter before deploying to production! -->
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

对于 JSF 1.2 (Facelets 1.x)参数是:

<context-param>
    <param-name>facelets.REFRESH_PERIOD</param-name>
    <param-value>0</param-value>
</context-param>
<context-param>
    <param-name>facelets.DEVELOPMENT</param-name>
    <param-value>true</param-value>
</context-param>

有关JSF上下文参数的更多信息:http://docs.jboss.org/jbossas/6/JSF_Guide/en-US/html/jsf.reference.html#standard.config.params

在您的情况下不需要自定义资源解析程序。该资源解析器只是从自定义文件系统文件夹中获取xhtml文件的一种棘手的方法。在你的情况下,JRebel会这样做(甚至更多)。

答案 1 :(得分:1)

以下是我为我解决的问题:

  1. 确认您的JRebel设置&amp;中已启用facelets插件
  2. 确认您在Project Stage
  3. 中使用Development web.xml
相关问题