JSF and automatic reload of xhtml files

[亡魂溺海] 提交于 2019-11-26 16:13:53

问题


I had some problems with hot-reloading XHTML 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?

回答1:


JRebel handles /WebContent folder changes.

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

<!-- 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>

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>

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




回答2:


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


来源:https://stackoverflow.com/questions/7512414/jsf-and-automatic-reload-of-xhtml-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!