我希望每次刷新@PostConstruct
bean中的页面时都会调用@RequestScoped
方法。但由于某种原因,它并没有。默认构造函数也不是。
我尝试使用filter
来禁用cache
,并且我看到它的doFilter
方法被调用,但它没有效果。
这是代码:
@ManagedBean
@RequestScoped
public class SearchResults implements Serializable {
public SearchResults() {
System.out.println("searchResults default constructor called");
}
@PostConstruct
public void init() {
System.out.println("SearchResults.init CALLED");
}
}
过滤器的相关方法:
public void doFilter(ServletRequest request, ServletResponse res, FilterChain chain) throws IOException, ServletException {
System.out.println("DisableCacheFilter.doFilter CALLED");
HttpServletResponse response = (HttpServletResponse) res;
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.
chain.doFilter(request, response);
}
我错过了什么?
编辑:这就是我所遗漏的:我将annotation
中的.java
从SessionScoped
更改为RequestScoped
,但将ManagedBean
作为会话范围在faces-config
。一旦我改变它,它开始按预期工作:
<managed-bean>
<managed-bean-name>searchResults</managed-bean-name>
<managed-bean-class>com.app.pages.SearchResults</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>