Changes in .xhtml file not reflected in browser, restart and build needed

旧时模样 提交于 2021-01-27 06:28:11

问题


If I make changes in my .xhtml file, the changes are not getting reflected on the screen in my browser. To get it to work, I have to restart the server everytime. This seems unwieldy to me.

I have added the following context parameters in my web.xml:

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
    <param-value>1</param-value>
</context-param>

However, they did not have any effect.

My technology stack is listed below:

  • SWF 2.3.0
  • Primefaces 2.2.1
  • JSF 2
  • Spring Security 3
  • Spring 3.1.0M1I
  • EhCache
  • Apache Tomcat 6.0
  • STS 2.5.1.

回答1:


If you're using an IDE, then you have to configure your IDE as well to publish changes to the server immediately. Otherwise the webapp which is running on the server won't get any notion of those changes.

As you're using STS which in turn is basically Eclipse for Java EE which is preloaded with a bunch of Spring specific plugins, I think that giving a generic Eclipse-targeted answer is more than sufficient.

In Eclipse, you just have to doubleclick the server entry in Servers view and then edit the Publishing section to set Automatically publish when resources changes and set the publishing interval as low as possible. It can even be 0 seconds.


enter image description here


That javax.faces.FACELETS_REFRESH_PERIOD only applies on the files in the webapp context. You just have to make sure that the IDE is publishing changes to the webapp context as soon as possible.




回答2:


I have just spent a couple of hours before finding out that adding antiResourceLocking="true" as an attribute to the <Context> element in the applications context.xml causes the same problem in Tomcat 7: changes in facelet files are not picked up; redeployment is needed.

Removing antiResourceLocking="true" or changing it to antiResourceLocking="false" makes Tomcat work as expected for development project stage.




回答3:


You should add those lines in your web.xml so that it will refresh whenever a change occurs in your .xhtml code.

<!--     JSF 2 (Facelets 2.x) -->
    <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>


来源:https://stackoverflow.com/questions/6997545/changes-in-xhtml-file-not-reflected-in-browser-restart-and-build-needed

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