I have a question surrounding faces navigation.
So I have a page that takes a request parameter to load a specific user. This page displays a list of commandLink
Basically, you need to tell the browser to not cache the dynamically generated JSF pages while having view state saving method set to (default) server. The view state is tracked by a <input type="hidden" name="javax.faces.ViewState"> field in the form of the generated JSF page with the view state identifier as input value. When you submit a page and navigate to a different page, then the view state is trashed in the server side and do not exist anymore. Getting the page back from the browser cache would still give you that old view state identifier as value of the hidden input. Submitting that form won't work at all as no view state in the server side can be found.
You want to get a fresh new page straight from the server instead of from the browser cache. In order to tell the browser to do that, create a Filter like this:
@WebFilter(servletNames={"Faces Servlet"})
public class NoCacheFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpReq = (HttpServletRequest) request;
HttpServletResponse httpRes = (HttpServletResponse) response;
if (!httpReq.getRequestURI().startsWith(httpReq.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) { // Skip JSF resources (CSS/JS/Images/etc)
httpRes.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
httpRes.setHeader("Pragma", "no-cache"); // HTTP 1.0.
httpRes.setDateHeader("Expires", 0); // Proxies.
}
chain.doFilter(request, response);
}
// ...
}
This way the back button will send a fullworthy HTTP request which should recreate the view state and result in a page with a form with the proper view state hidden field value.