开发者

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

开发者 https://www.devze.com 2023-03-27 07:34 出处:网络
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 un开发者_StackOverflow中文

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 un开发者_StackOverflow中文版wieldy 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.


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.


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


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.


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消