+ Start a Discussion
Vivek ViswanathVivek Viswanath 

Passing data between pages using controllers

Hi

I was trying to pass data between pages using the controller which failed. Is this possible every time I redirect I loose the state of the controller.

I have two pages with the same controller can I keep the data in the controller when I move from one page to the other sharing the data betweent he pages.

Regards

Vivek


Message Edited by Vivek Viswanath on 07-22-2008 10:50 AM

Message Edited by Vivek Viswanath on 07-22-2008 10:51 AM
Ron HessRon Hess
please see the visualforce docs, read the wizard example

http://www.salesforce.com/us/developer/docs/pages/Content/pages_quick_start_wizard.htm

here is a snippet

Code:
 // The next three methods control navigation through
   // the wizard. Each returns a PageReference for one of the three pages
   // in the wizard. Note that the redirect attribute does not need to
   // be set on the PageReference because the URL does not need to change
   // when users move from page to page.
   public PageReference step1() {
      return Page.opptyStep1;
   }

   public PageReference step2() {
      return Page.opptyStep2;
   }

   public PageReference step3() {
      return Page.opptyStep3;
   }

 
if you use setRedirect(true) you will erase all values in the controller.


Message Edited by Ron Hess on 07-22-2008 11:03 AM

Message Edited by Ron Hess on 07-22-2008 11:05 AM
Vivek ViswanathVivek Viswanath
Hi,

I was using that as my example however was having trouble when I was putting an action on the apex page

here is the code:

public PageReference init()
        {
            setOpportunityId(); // sets the id from the url only if its null or empty
   
            return registrationKitReOrder();
        }

public PageReference registrationKitReOrder()
    {
         return Page.TestPage;
    }

<apexage controller="SFDCRegKitController" action="{!init}" >
</apexage>

This is my page I put in debug statements and it goes into that part of the code and also returns the page. However its not displayed. Please let me know what I am doing wrong here
I got a post saying this is a known issue and hence I change it as suggest to the following


public PageReference registrationKitReOrder()
    {
        PageReference reorder = Page.TestPage;
        reorder.setRedirect(true);
        return reorder;
    }

which works in directing it to the second page however fails to carry the data over








Message Edited by Vivek Viswanath on 07-22-2008 11:35 AM
Ron HessRon Hess
If it's a known issue , then you are not doing anything wrong.

Try this:
you can do a setRedirect() then after that i think you can add a parameter to the page, then return the page

public PageReference registrationKitReOrder()
    {
        PageReference reorder = Page.TestPage;
        reorder.setRedirect(true);
        reorder.getParameters().put('id', getOpportunityId() );      
        return reorder;
    }








Vivek ViswanathVivek Viswanath
Hi,

I am using that though i can pass the opportunity Id there is a lot more data than just the opp id, I was concerned about re-quering for data and was hoping for another workaround :D.

Regards

Vivek


Message Edited by Vivek Viswanath on 07-22-2008 11:46 AM
Ron HessRon Hess
if you pass the data on the query string you don't have to re-query, otherwise you will.
vipulpahwavipulpahwa

I am facing the same 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?