This is a problem I inherited. We have a JSF/RichFaces/Seam app, which for security reasons has no-cache set. The problem comes when users hit the back-button, causing a repost of a form. Sometimes (and it is inconsistent) the form re-POST after hitting the back-button sets the backing bean properties to null. When caching is set to private, this does not happen. Unfortunately, that is not an option.
I have been looking for a workaround for this, and I'm not sure there is one.
Does anyone know of a standard pattern to use for this?
Yes, the Post-Redirect-Get pattern. Add
<redirect/>
to your navigation cases of interest to perform a redirect to a GET request after a POST. The back button would then go to the GET request instead. In JSF 2.x, you can also do this by adding?faces-redirect=true
parameter to the outcome.It has however a disadvantage when your webapplication poorly developed in such way that you're sending POST requests from page-to-page instead of POST requests to self (preferably ajax-flavored). This way any request scoped bean is not available anymore in the redirected GET request.
Also, when you're using commandlinks instead of outputlinks for plain vanilla page-to-page navigation (e.g. menu links, etc), then those should be fixed to outputlinks. Using POST has totally no value here, they should be GET from the beginning on.
Ideally, for sure in JSF 1.x webapps, you should not have any navigation cases at all if you want optimal SEO, bookmarkability and user experience.