We use JSF2, we have a page with form fields with command button linked to backing bean.
When we access the form page, enter the values and submit, the backing bean recieves the correct values and takes it to the next page. If I press back button in the browser, it takes to previous page with form. If I enter new values in the form and submit, the backing bean still recieves the old values in Step 1.
This is odd. Perhaps your bean is put in the session scope and/or the browser has requested the page from the cache. To start, you'd like to disable browser cache for all dynamic pages by a filter which sets the proper response headers.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
if (!req.getRequestURI().startsWith(req.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) { // Skip JSF resources (CSS/JS/Images/etc)
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
res.setHeader("Pragma", "no-cache"); // HTTP 1.0.
res.setDateHeader("Expires", 0); // Proxies.
}
chain.doFilter(request, response);
}
Map this filter on the servlet name of the FacesServlet
or on the same URL pattern.
Last, but not least, do not put your form beans in the session scope. Put them in the request or view scope.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With