You need to sign in to do that
Don't have an account?
App_Dev1
Passing data between controllers
Say I have page A which uses controller X, and page B controller Y. I want some continuity between the pages so that some variables in X are passed to Y when the user clicks a link in page A to visit page B.
I've implemented this with commandLink. The action method in X which transitions to page B includes a bunch of code that copies the relevant state variables into the request parameters. Example:
public PageReference goPageB() {
I've implemented this with commandLink. The action method in X which transitions to page B includes a bunch of code that copies the relevant state variables into the request parameters. Example:
public PageReference goPageB() {
PageReference ref = Page.pageB;
ref.getParameters().put('p1', p1);
ref.getParameters().put('p2', p2);
ref.setRedirect(true);
return ref;
}
This works fine. But I'm wondering if there's a better way. I'd rather pass the variables in a POST, or in a shared session object that both pages reference.
We are also looking at providing some form of object-based state passing in the Summer '08 timeframe that would allow you to marshall complex object refs from one controller to another but I am just starting the design work for that...
I've found, at least with the Summer '10 release, that not only does the controller have to be the same, the extensions must also be the same in order to pass data from page to page.
"Passing Data between Visualforce Pages with Controllers and Extensions"
http://frombelvideres4thfloor.blogspot.com/2010/08/passing-data-between-visualforce-pages.html
I am facing a similar issue...Here is the code
PAGE - FirstPage
<apex:page standardController="Design__c" extensions="DesignController" action="{!init}">
<!-- SOME TEXT DISPLAYED -->
<apex:outputpanel>
<apex:commandButton action="{!openSecondPage}" value="Open Second Page"/>
</apex:outputpanel>
</apex:page>
CLASS
global class DesignController {
public DesignController(ApexPages.StandardController controller){
parentId = controller.getRecord().Id;
}
public PageReference init(){
application = new MetadataWrapper.Application();
....
//PERFORM SOME ACTION TO POPULATE application object
...
return null;
}
public PageReference openSecondPage(){
return Page.SecondPage;
}
public Class Wrapper {
public String name {get; set;}
public String typr {get; set;}
public Boolean isSelected {get; set;}
public Wrapper(String name, String type, Boolean isSelected){
this.name = name;
this.type = type;
this.isSelected = isSelected;
}
}
}
In this case if I dont set setRedirect to true, on the click of the button, the page (FirstPage) reloads again thereby invoking the action function (init) and the second page (SecondPage) does not load.
However, if i do set setRedirect to true, the SecondPage loads but the data (application object) is not passed through.
Any thoughts on how this behaviour can be rectified?