JSF how to force hard reload of current page

青春壹個敷衍的年華 提交于 2019-12-08 02:34:19

问题


I use JSF 1.2. I have a view in which I have a h:commandButton with the following action:

#{myBean.saveSomeData}

When I click on the button, I want to save some data and like the data that are saved can change the display of my view, i would like to force hard reload (like a CTRL+F5 in my browser for example) of my page.

To do that, I thought to this code :

public void saveSomeData() {
            ... Save some data ... 

        FacesContext context = FacesContext.getCurrentInstance();
        String viewId = context.getViewRoot().getViewId();
        ViewHandler handler = context.getApplication().getViewHandler();
        UIViewRoot root = handler.createView(context, viewId);
        root.setViewId(viewId);
        context.setViewRoot(root);
}

But when i do that, the tree components of my view is not reloaded.

So, I don't know how to do that reload. Someone would have any idea about the way to do that ?

Thanks by advance for your help.

Sylvain.


回答1:


Add no-cache headers to the response so that the browser never caches the page. You can do this with a Filter which is mapped on the url-pattern of interest. For example *.jsf or just on the FacesServlet. Let the Filter set the following headers in the doFilter() method:

response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setDateHeader("Expires", 0); // Proxies.


来源:https://stackoverflow.com/questions/5301530/jsf-how-to-force-hard-reload-of-current-page

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