function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
robertcw777robertcw777 

Sharing variables on included visualforce pages

I have a visualforce page that shows charts that I would like to filter based on a filter header  settings. For example, when the user selects a specific Country, the charts will be rerendered for just that country data.  Below is the controller for the filter page showing the dropdown values. Below that is the master page that includes the filter page, and other visualforce pages that display the charts, each with its own controller. How can I share the value of the dropdown selection wiht the controllers for the included pages?

 

Thanks!

 

public with Sharing class PracticeFilterClass{

 

// public List<SelectOption> Filter {get;set;}
 
public String SelectedFilter{get;set;}
public String SelectedRegion{get;set;}
public String SelectedCountry{get;set;}
public String SelectedStateProvince{get;set;}
public String SelectedCity{get;set;}
public String SelectedRole{get;set;}

 

etc...

 

VisualForcePage:

 

<apex:page >
<apex:include pageName="FilterHeaderPage"/>
<apex:include pageName="MyDashboardInfo"/>
<apex:include pageName="MyDashboardRow2"/>
</apex:page>

 

 

Best Answer chosen by Admin (Salesforce Developers) 
robertcw777robertcw777

Nice solution. Thank you!

All Answers

Neeraj_ChauriyaNeeraj_Chauriya

Hi,

 

You can use merge fields to dynamically provide page reference in pageName attribute of <apex:include> tag.

Upon selecting a filter value you should update the page reference for the included pages by passing the parameter values in the url string and rerender the panel in which you have included the other pages.

 

Apex controller:

public with Sharing class PracticeFilterClass{ 

// public List<SelectOption> Filter {get;set;}
 
public String SelectedFilter{get;set;}
public String SelectedRegion{get;set;}
public String SelectedCountry{get;set;}
public String SelectedStateProvince{get;set;}
public String SelectedCity{get;set;}
public String SelectedRole{get;set;}

public PageReference FilterHeaderPageURL { 
get{
/*create page reference by passing the parameters in the url of the page and use the parameter values in the controller of the page.*/
return new PageReference('/apex/FilterHeaderPage?yourVar=yourValue');
}
set;
}
/*Create pagereference for all the pages for which you want to pass the vales dynamically*/
}

 

 VF Page:

<apex:page >
<!-- rerender the below panel upon changing the filter values from dropdowns -->
<apex:outputPanel id="included-pages">
<apex:include pageName="{!FilterHeaderPageURL}"/>
<apex:include pageName="{!MyDashboardInfoURL}"/>
<apex:include pageName="{!MyDashboardRow2}"/>
</apex:outputPanel>
</apex:page>

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other's benefit.

 

robertcw777robertcw777

Nice solution. Thank you!

This was selected as the best answer