JSF 和 Facelets 文件的自动重新加载

发布于 2024-12-05 15:40:26 字数 626 浏览 0 评论 0原文

我在使用 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技术交流群

发布评论

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

评论(2

酒与心事 2024-12-12 15:40:26

JRebel 处理 /WebContent 文件夹更改。

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

JSF 2+ (Facelets 2+):

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

这会自动将“Facelets 刷新周期”配置设置为 0,从而有效禁用 Facelets 缓存。

或者,如果您不想更改项目阶段,则

<!-- Time in seconds that Facelets should be checked for changes since last request. A value of -1 disables auto-refresh. -->
<!-- You should remove this context parameter before deploying to production or use PROJECT_STAGE instead! -->
<context-param>
    <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
    <param-value>0</param-value>
</context-param>

对于 Faces 4.x,javax. 前缀应为 jakarta.,如下所示 jakarta .faces.PROJECT_STAGEjakarta.faces.FACELETS_REFRESH_PERIOD


对于 JSF 1.2 (Facelets 1.x),等效参数为:

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

有关 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+):

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

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

<!-- Time in seconds that Facelets should be checked for changes since last request. A value of -1 disables auto-refresh. -->
<!-- You should remove this context parameter before deploying to production or use PROJECT_STAGE instead! -->
<context-param>
    <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
    <param-value>0</param-value>
</context-param>

For Faces 4.x the javax. prefix should be jakarta. instead, like so jakarta.faces.PROJECT_STAGE and jakarta.faces.FACELETS_REFRESH_PERIOD.


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

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

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

§对你不离不弃 2024-12-12 15:40:26

以下是我解决此问题的方法:

  1. 验证您的 JRebel 设置中是否启用了 facelets 插件。
  2. 验证您是否在 web.xml 中使用 Project Stage Development

Here's how I fixed this for me:

  1. Verify that facelets plugin is enabled in your JRebel settings &
  2. Verify that you're using Project Stage Development in your web.xml
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文