JSF如何强制硬重装当前页面 [英] JSF how to force hard reload of current page
问题描述
我使用JSF 1.2.我有一个视图,其中有一个h:commandButton,它具有以下操作:
I use JSF 1.2. I have a view in which I have a h:commandButton with the following action:
#{myBean.saveSomeData}
当我单击按钮时,我想保存一些数据,就像保存的数据可以改变视图的显示一样,我想强制重新加载(例如在浏览器中按CTRL + F5)页面上的内容.
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 ?
在此先感谢您的帮助.
西尔万.
推荐答案
在响应中添加无缓存标头,以使浏览器从不缓存页面.您可以使用Filter
来做到这一点,该Filter
映射在目标url模式上.例如*.jsf
或仅在FacesServlet
上.让Filter
在doFilter()
方法中设置以下标头:
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.
这篇关于JSF如何强制硬重装当前页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!