2

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.

sylsau
  • 413
  • 9
  • 19

1 Answers1

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.
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555