Access a variable on a controller on two seperate visualforce pages

1.6k views Asked by At

I have two visual force pages that use the same controller. There a few fields which I set on the first visual page which I would like to access on the second visualforce page. I was wondering how I could accomplish this?

Here is what I currently have in my controller:

// most functions have been removed. 
public with sharing class someController{

    //standard controller declarations
    private ApexPages.StandardController controller {get;set;}

    public String identifier {get;set;} //This is the field I want to access on both pages


     /**
     * Constructor
     **/
    public DeviceLookupController(ApexPages.StandardController controller) {

        this.controller = controller;

    }
}

Essentially, I want the identifier field to be available on two visualforce pages from the someController.

The someController that is shown above is an extension to both pages, and the standardController is set as the same object on both pages.

2

There are 2 answers

0
Raul On

Something similar is implemented in the documentation.

You man want to have a look at it.

0
kapcsbit On

AlvinJ,

I see that you are using Same standard controller and extension in both the pages. It seems they have, more likely, similar functionalities. Following are the options i could suggest from the given information:

  1. Merge VF pages : Use Boolean variable for conditional render of VF components

<apex:pageBlockSection id="xxxpbs1" rendered="{!ShowPage1}">

</apex:pageBlockSection>

<apex:pageBlockSection id="xxxpbs2" rendered="{!ShowPage2}">
                                                                     
</apex:pageBlockSection>

  1. Query string : If you have just one or two identifiers and security is not a concern then please pass the identifier variable via query string. Please find below a link to an example of query string Getting Query String Parameters

Let me know if you need more details.

Thanks