Paul Klaer wrote:
You don't need to capture the back button.

Just add this js snippet to your javascript on each page: "history.forward();"

Interesting - so if the user has used the app normally (ie not used the back button) then history.forward does nothing. But if they have used back, then as soon as the previous page loads it jumps *forward* to the page they were on when they hit the back button, effectively making "back" act like a "refresh" button?

The traditional mechanism for preventing people from using the back button is to have a hidden field in every page with a counter value, and have a corresonding counter value in the user's session. The counter is incremented each time a page is served. If a request comes in and the values don't match then the user must have used the back button, so they are redirected to a page telling them not to do that. I'm not aware of any JSF tag that implements this but I wouldn't be surprised to find one exists.

I believe that storing user state in the page rather than in the session can help with making an app work even when the back button is used. This can be enabled in web.xml:
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
        <description>
            State saving method: "client" or "server"
        </description>
    </context-param>
I haven't experimented with this myself though.

Regards,

Simon

Reply via email to