If you create something like a shopping cart or a βwizardβ where you need to keep controller variables in context from one page view to another, then the best way to do this in VisualForce is to use the same controller.
When a user submits a form (via actionFunctions, commandButtons or commandLinks, etc.) and your controller returns a link to the page, the view state is saved if the new page of visual power uses the same controller.
Thus, you can, for example, specify the username and email address using apex: inputField tags on the first page. They go to page two, which uses the same controller as the first page, and the page can refer to the same controller variables. Essentially, the controller is still in scope, and all the variables that were updates are.
Example:
Page One:
<apex:page controller="myController"> Please enter your name <apex:inputText value="{!shopper_name}"/> <br/> <apex:commandButton action="{!pageTwo}" value="Click for page two"/> </apex:page>
Page Two:
<apex:page controller="myController"> You entered: <apex:outputText value="{!shopper_name}" />. </apex:page>
Controller:
public class myController { public string shopper_name { get; set; } public myController() { shopper_name = null; } }
source share