我在使用 JRebel、Spring、JSF Mojarra 2.0.3 和 WebLogic 10.3 热重载 XHTML 文件时遇到了一些问题。
JRebel 成功地重新加载了/WebContent 下的常规 Java 类和 js/css 文件,但不是 JSF 的 .xhtml 文件。需要完全重新发布才能在服务器上更新 xhtml 文件。
通过反复试验,我终于通过向 web.xml 添加一些 facelets 参数并创建自定义 ResourceResolver 来使其工作,如 in this blog post 所述.
但是,我想知道为什么会这样,更具体地说:
- 为什么需要自定义 ResourceResolver?
- JRebel 不应该通过监视 xhtml 文件所在的/WebContent 来处理这个问题吗?
- 我猜这与 Facelets/JSF 通过 FacesServlet 将 xhtml 编译为 servlets(?)有关,而 JRebel 无法检测到?
最佳答案
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 会这样做(甚至更多)。
关于java - JSF 和 xhtml 文件的自动重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7512414/