function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Mulitple VF pages with one controller: controlling app state

I've set up 3 VF pages to use one controller. As I navigate from page to page, certain state data is being held in variables in the controller. It generally works.

However, the URL in the address bar isn't showing the correct page. I start on page A and when I move to page B via a command link, the URL isn't updating. It appears to stay one page behind.

Here's an example of how I'm moving from one page to the next:
    public PageReference loadCallList() {
      //set the current campaign
     //set the list of members
  //redirect to the call list page
  return Page.callList;

 If I set the Redirect parameter to true, the URL changes but I also lose my state information.

What am I missing about navigating between pages while not reinstantiating my controller?


David VPDavid VP
An educated gues here :

To me it seems normal behaviour (just as with Struts and JSF).
The server processes your request and the Java code there (which is actually running the show) does a server side 'forward'. It is basically tunneling the request to code responsible for building the next page without the browser being aware of it (this code also keeps track of your viewstate and in-memory variables). That's why your url always is one page behind.

The other option that exists is a 'redirect' which basically sends an answer back to the browser telling it to 'redirect' (basically perform a 'brand new' http GET) to another page (loosing the in memory viewstate).

Check out any JSF based website and you'll see the same behaviour.


Correct - with the addition that many other frameworks, e.g. ASP.NET, also make use of the viewstate concept in much the same way.
Thanks David and Doug, that makes sense.

I broke out the controllers to 1 per page and passed my variables on the querystring. Works great.