Sunday, November 20, 2011

CLIENT_STATE_MAX_TOKENS = 1 for Browser Back Button Control

There is documented approach which allows to control web browser back button. This approach works for ADF 11g applications implemented with pages and ADF Task Flows based on pages (doesn't work with ADF fragments).

The trick is to set org.apache.myfaces.trinidad.CLIENT_STATE_MAX_TOKENS = 1. This means, ADF will preserve only one client token in memory, once user will press browser back button - this token will be lost. On the next user click - application will reset to its initial state, this will ensure predictable behavior.

Download sample application - BackButtonExpire.zip. This sample implements sequence of ADF Task Flows with pages, first it defines Departments call:


Next is Employees call:


Employees Task Flow contains Return activity to navigate back to Departments:


As per documentation, we set org.apache.myfaces.trinidad.CLIENT_STATE_MAX_TOKENS = 1 in web.xml:


When we test this, lets open last Task Flow from the sequence - Employees. Press browser back button now:


Page from previous Departments Task Flow is opened - however client token will be already lost, as per our configuration. This is helpful if we want to avoid broken data, now if user performs any action - current page will be reset and reloaded:


Reload happens:


Page is reinitialized with fresh client token:


4 comments:

Spyros Doulgeridis said...

Nice approach but with the value 1 user can have only one window of the application open at the time. He cannot have 2 or more windows of the application of the same time, e.g. search from Departments while editing an employee.

Is there a way to achieve this too?

Spyros

Andrej Baranovskij said...

I have tested with 2 opened tabs on IE and Firefox, it seems to work fine. What is your test case?

Andrejus

Unknown said...

Some components stop working correctly when the CLIENT_STATE_MAX_TOKENS is set to 1, I tried the af FileUpload with allowance for multiple files and once I upload something and press any button in the application the system crashes with an expired view state error, do you know any way around this?

Andrej Baranovskij said...

Hi,

I suggest to migrate to 12c: http://andrejusb.blogspot.com/2014/09/jdeveloper-12c-adf-view-token.html

It works much better with View Tokens, you can leave default setting.

Regards,
Andrejus