JSF 和自动重新加载 xhtml 文件 [英] JSF and automatic reload of xhtml files

查看:24
本文介绍了JSF 和自动重新加载 xhtml 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 JRebel、Spring、JSF Mojarra 2.0.3 和 WebLogic 10.3 热重载 XHTML 文件时遇到了一些问题.

I had some problems with hot-reloading XHTML files using JRebel, Spring, JSF Mojarra 2.0.3 and WebLogic 10.3.

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

JRebel reloads regular Java classes and js/css files under /WebContent successfully, but not JSF's .xhtml files. A full republish was necessary to get xhtml files updated on the server.

通过反复试验,我终于通过向 web.xml 添加一些 facelets 参数并创建自定义 ResourceResolver 来使其工作,如 在这篇博文中.

By trial and error I finally got it to work by adding some facelets parameters to web.xml and creating a custom ResourceResolver as described in this blog post.

但是,我想知道为什么会这样,更具体地说:

However, I wonder WHY this works, and more specifically:

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

推荐答案

JRebel 处理/WebContent 文件夹更改.

JRebel handles /WebContent folder changes.

问题在于 Facelets 会缓存并且不会重新读取更改过的文件.要强制重读,​​请在 web.xml 中指定以下参数.

The problem is that Facelets do caching and do not reread changed files. To force reread specify the following parameters in web.xml.

JSF 2(Facelets 2.x):

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) 参数是:


For JSF 1.2 (Facelets 1.x) parameters are:

<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

More on JSF context params: http://docs.jboss.org/jbossas/6/JSF_Guide/en-US/html/jsf.reference.html#standard.config.params

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

That custom resource resolver is not needed in your case. That resource resolver is just a tricky way to get xhtml files from custom file system folder. In your case JRebel does that (and even more).

这篇关于JSF 和自动重新加载 xhtml 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆