JSF 和 Facelets 文件的自动重新加载
我在使用 JRebel、Spring、JSF Mojarra 2.0.3 和 WebLogic 10.3 热重载 Facelets 文件时遇到了一些问题。
JRebel 成功重新加载 /WebContent 下的常规 Java 类和 js/css 文件,但不能成功加载 JSF 的 .xhtml 文件。需要完全重新发布才能在服务器上更新 xhtml 文件。
经过反复试验,我终于通过向 web.xml 添加一些 Facelets 参数并创建自定义 ResourceResolver 使其工作,如所述 在此博文中。
但是,我想知道为什么这有效,更具体地说:
- 为什么需要自定义 ResourceResolver?
- JRebel 不应该通过监视 xhtml 文件所在的 /WebContent 来处理这个问题吗?
- 我猜这与 Facelets/JSF 通过 FacesServlet 将 xhtml 编译为 servlet(?)有关,而 JRebel 无法检测到?
I had some problems with hot-reloading Facelets files using JRebel, Spring, JSF Mojarra 2.0.3 and WebLogic 10.3.
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.
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:
- Why is a custom ResourceResolver needed?
- Isn't JRebel supposed to handle this by monitoring /WebContent where the xhtml files reside?
- I'm guessing it has something to do with Facelets/JSF compiling xhtml to servlets(?) via FacesServlet which JRebel is unable to detect?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JRebel 处理 /WebContent 文件夹更改。
问题是 Facelets 会进行缓存并且不会重新读取已更改的文件。要强制重新加载,请在
web.xml
中指定以下参数之一。JSF 2+ (Facelets 2+):
这会自动将“Facelets 刷新周期”配置设置为 0,从而有效禁用 Facelets 缓存。
或者,如果您不想更改项目阶段,则
对于 Faces 4.x,
javax.
前缀应为jakarta.
,如下所示jakarta .faces.PROJECT_STAGE
和jakarta.faces.FACELETS_REFRESH_PERIOD
。对于 JSF 1.2 (Facelets 1.x),等效参数为:
有关 JSF 上下文参数的更多信息:http://docs.jboss.org/jbossas/6/JSF_Guide/en-US/html/jsf.reference.html#standard.config.params
您的情况不需要该自定义资源解析器。该资源解析器只是从自定义文件系统文件夹获取 xhtml 文件的一种棘手方法。在你的例子中,JRebel 做到了这一点(甚至更多)。
JRebel handles /WebContent folder changes.
The problem is that Facelets do caching and do not reread changed files. To force reload specify one of the following parameters in
web.xml
.JSF 2+ (Facelets 2+):
This will automatically set the "Facelets refresh period" configuration to 0, hereby effectively disabling the Facelets cache.
Or, if you don't want to change the project stage, then
For Faces 4.x the
javax.
prefix should bejakarta.
instead, like sojakarta.faces.PROJECT_STAGE
andjakarta.faces.FACELETS_REFRESH_PERIOD
.For JSF 1.2 (Facelets 1.x) the equivalent parameters are:
More on JSF context params: http://docs.jboss.org/jbossas/6/JSF_Guide/en-US/html/jsf.reference.html#standard.config.params
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).
以下是我解决此问题的方法:
facelets
插件。web.xml
中使用Project Stage
Development
Here's how I fixed this for me:
facelets
plugin is enabled in your JRebel settings &Project Stage
Development
in yourweb.xml