session   Leave a comment

If you are building 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 the user submits a form ( through actionFunctions, commandButtons, or commandLinks, etc.), and your controller returns a page Reference, the view state is preserved if the new visual force page uses the same controller.

In this way, you could, for example, have the user enter their name and email address using apex:inputField tags on page one. They navigate to page two, which uses the same controller as page one, and the page could reference the same controller variables. Essentially, the controller is still in scope, and so are all the variables that were updates.


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> 


public class myController { public string shopper_name { get; set; } public myController() { shopper_name = null; } }

Posted 2011年08月1日 by gw8310 in salesforce


Fill in your details below or click an icon to log in: 徽标

You are commenting using your account. Log Out /  更改 )

Google+ photo

You are commenting using your Google+ account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

Connecting to %s

%d 博主赞过: