+ Start a Discussion
BittusBittus 

How to display a vf page in page block section of another vf page

Hello,
Here i have a vf page which displays two drop downs, i mean controlling picklist (Region) and dependent picklist(Fields).
I need to display another vf page in the same vf page when we select a field in second drop down.
Am able to redirect to another vf page when we select a field value. 
Instead of redirecting to another vf page using page reference, i want to display that vf page in the same page under the drop down fields section.
Here is my code

VF Page:-
-------------------------

<apex:page controller="TestDashboard">
    <apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection columns="2">
            
         <apex:outputLabel value="Region"/>
            <apex:pageblockSectionItem >                
                <apex:selectList size="1" value="{!Region}">
                    <apex:selectOptions value="{!Regions}"/>
                    <apex:actionSupport event="onchange" reRender="a"/>
                </apex:selectList>                
            </apex:pageblockSectionItem>
                <apex:outputLabel value="Fields"/>
            
            <apex:selectList value="{!Field}" size="1" >
     <Apex:selectOptions value="{!item}"/>
    <apex:actionSupport event="onchange" action="{!redirect}" />    
     </apex:selectList>
        </apex:pageBlockSection>    
       
    </apex:pageBlock>

    </apex:form>

</apex:page>


Controller:-
--------------------

public class TestDashboard {
    public String Region {get;set;}
    public String Field {get;set;}
    public list<selectoption>item{get;set;}
    public TestDashboard()
{
    item=new list<selectoption>();
    item.add(new selectoption('','---None----'));
    item.add(new selectoption('SplitTabs','PipeLine'));
    item.add(new selectoption('MULChart','Commit'));
}
 
public pagereference redirect()
{
     PageReference pageRef= new PageReference('/apex/' +Field);
    pageRef.setredirect(true);
    return pageRef;
}
    public List<SelectOption> getRegions()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('None','--- None ---'));        
        options.add(new SelectOption('A','Great Lakes(Tom Leone)'));
        options.add(new SelectOption('A','Metro NY/NJ(Rachel Sama)'));
        options.add(new SelectOption('A','Mid Atlantic(Rob Newman)'));
        options.add(new SelectOption('A','Mid West(Jim Stanley)'));
        options.add(new SelectOption('A','New England(Tony Messina)'));
        options.add(new SelectOption('A','South Central(Hector vallejo)'));
        options.add(new SelectOption('A','South East(Jeff Nelson)'));
        options.add(new SelectOption('A','Central(David Neuner)'));
        options.add(new SelectOption('A','Mountain Plains(Jared Holmes)'));
        options.add(new SelectOption('A','Northern California(Chad Petric)'));
        options.add(new SelectOption('A','N.Central(Michael Robinson)'));
        options.add(new SelectOption('A','North West(Rick Estes)'));
        options.add(new SelectOption('A','Southern California(Dennis Zanrosso)'));
        options.add(new SelectOption('A','South West(Chris Crospy)'));
        options.add(new SelectOption('A','US East'));
        options.add(new SelectOption('A','US West'));
        return options;
    } 
    
    public List<SelectOption> getFields()
    {
        List<SelectOption> options = new List<SelectOption>();
        if(Region == 'A')
        {       
            options.add(new SelectOption('None','--- None ---'));
            options.add(new SelectOption('PipeLine','PipeLine'));
            options.add(new SelectOption('Actuals','Actuals'));
            options.add(new SelectOption('Commit','Commit'));
            options.add(new SelectOption('OP(Operating Plan','OP(Operating Plan)'));
            options.add(new SelectOption('Run Rate Opp','Run Rate Opp'));
            options.add(new SelectOption('Quote Min Vlaue','Quote Min Vlaue'));
            options.add(new SelectOption('No.of Opp With Quotes','No.of Opp With Quotes'));
            options.add(new SelectOption('No.of Quotes','No.of Quotes'));
            options.add(new SelectOption('BestCase','BestCase'));
            options.add(new SelectOption('Spec Dollars','Spec Dollars'));
            options.add(new SelectOption('BestCase Count','BestCase Count'));
            options.add(new SelectOption('No.of Opp with Spec Flag','No.of Opp with Spec Flag'));
            options.add(new SelectOption('% vCommit','% vCommit'));
            options.add(new SelectOption('% vOP','% vOP'));
            options.add(new SelectOption('Calls Logged','Calls Logged'));
            
        }
        
        else if(Region == 'KL')
        {       
            options.add(new SelectOption('COA','Coachin'));
            options.add(new SelectOption('MVL','Mavelikara'));
        }
        else
        {
            options.add(new SelectOption('None','--- None ---'));
        }      
        return options;
    }
    
}
Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi Bittus,
Use this in your PageBlock,
<apex:ouputPanel id="secondPageId" rendered="{!condition}">
     <apex:include pageName="YourSecondVfPageName"/>
</apex:outputPanel>


and create a field in your controller named condition and use ths variable to  rerender the outputpanel whenever your requirement meets.
BittusBittus
Hi Prosenjt,

In the vf page which i mentione above, i added <apex:include pageName="MySecondVfPageName"/> in my vf page.
I am able to get the MySecondVfPage in the Main page. But, i need to display  MySecondVfPage in Main page only when i select a field (pipeline/commit) from dropdown.

Can u please edit my code to get this work
 
Prosenjit Sarkar 7Prosenjit Sarkar 7
Yea, sure I will edit that.
Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi Bittus,

Please try this code and let me know if some error/exception occured due to this code,

Visualforce Page : 
 
<apex:page controller="TestDashboard">
    <apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection columns="2">
            <apex:outputLabel value="Region"/>
			
			<apex:pageblockSectionItem >                
				<apex:selectList size="1" value="{!Region}">
					<apex:selectOptions value="{!Regions}"/>
					<apex:actionSupport event="onchange" reRender="a"/>
				</apex:selectList>                
			</apex:pageblockSectionItem>
			
			<apex:outputLabel value="Fields"/>
			
			<!-- Start : Code Modified by Prosenjit -->	
			<apex:selectList value="{!Field}" size="1" onchange="showSecondPage(this.value);">
				<apex:selectOptions value="{!item}"/>
			</apex:selectList>
			<!-- End : Code Modified by Prosenjit -->
		</apex:pageBlockSection>    
        
		<!-- Start : Code Written by Prosenjit -->
		<apex:ouputPanel id="secondPagePanel" rendered="{!secondPageToBeShown}">
			<apex:pageBlockSection columns="1">
				<apex:include pageName="YourSecondVfPageName"/>
			</apex:pageBlockSection>
		</apex:outputPanel>
		<!-- End : Code Written by Prosenjit -->
    </apex:pageBlock>

    </apex:form>
	
	<apex:form >
        <apex:actionFunction action="{!showSecodPageOrNot}" name="showSecondPage" reRender="secondPagePanel">
            <apex:param assignTo="{!fieldValue}" value="" name="fieldValue"/>
        </apex:actionFunction>
    </apex:form>
</apex:page>

 
Prosenjit Sarkar 7Prosenjit Sarkar 7
And here the Controller : 

public class TestDashboard {
    public String Region {get;set;}
    public String Field {get;set;}
    public list<selectoption>item{get;set;}
    /* Start : Code Written by Prosenjit */
    public Boolean secondPageToBeShown{get;set;}
    public String fieldValue{get;set;}
    /* End : Code Written by Prosenjit */
    public TestDashboard()
    {
        item=new list<selectoption>();
        item.add(new selectoption('','---None----'));
        item.add(new selectoption('SplitTabs','PipeLine'));
        item.add(new selectoption('MULChart','Commit'));
        secondPageToBeShown = false; // Line Added by Prosenjit
    }
 
    public pagereference redirect()
    {
        PageReference pageRef= new PageReference('/apex/' +Field);
        pageRef.setredirect(true);
        return pageRef;
    }
    /* Start : Code Written by Prosenjit */
    public void showSecodPageOrNot() {
        if(fieldValue=='PipeLine')
            secondPageToBeShown = true;
    }
    /* End : Code Written by Prosenjit */
    public List<SelectOption> getRegions()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('None','--- None ---'));        
        options.add(new SelectOption('A','Great Lakes(Tom Leone)'));
        options.add(new SelectOption('A','Metro NY/NJ(Rachel Sama)'));
        options.add(new SelectOption('A','Mid Atlantic(Rob Newman)'));
        options.add(new SelectOption('A','Mid West(Jim Stanley)'));
        options.add(new SelectOption('A','New England(Tony Messina)'));
        options.add(new SelectOption('A','South Central(Hector vallejo)'));
        options.add(new SelectOption('A','South East(Jeff Nelson)'));
        options.add(new SelectOption('A','Central(David Neuner)'));
        options.add(new SelectOption('A','Mountain Plains(Jared Holmes)'));
        options.add(new SelectOption('A','Northern California(Chad Petric)'));
        options.add(new SelectOption('A','N.Central(Michael Robinson)'));
        options.add(new SelectOption('A','North West(Rick Estes)'));
        options.add(new SelectOption('A','Southern California(Dennis Zanrosso)'));
        options.add(new SelectOption('A','South West(Chris Crospy)'));
        options.add(new SelectOption('A','US East'));
        options.add(new SelectOption('A','US West'));
        return options;
    } 
    
    public List<SelectOption> getFields()
    {
        List<SelectOption> options = new List<SelectOption>();
        if(Region == 'A')
        {       
            options.add(new SelectOption('None','--- None ---'));
            options.add(new SelectOption('PipeLine','PipeLine'));
            options.add(new SelectOption('Actuals','Actuals'));
            options.add(new SelectOption('Commit','Commit'));
            options.add(new SelectOption('OP(Operating Plan','OP(Operating Plan)'));
            options.add(new SelectOption('Run Rate Opp','Run Rate Opp'));
            options.add(new SelectOption('Quote Min Vlaue','Quote Min Vlaue'));
            options.add(new SelectOption('No.of Opp With Quotes','No.of Opp With Quotes'));
            options.add(new SelectOption('No.of Quotes','No.of Quotes'));
            options.add(new SelectOption('BestCase','BestCase'));
            options.add(new SelectOption('Spec Dollars','Spec Dollars'));
            options.add(new SelectOption('BestCase Count','BestCase Count'));
            options.add(new SelectOption('No.of Opp with Spec Flag','No.of Opp with Spec Flag'));
            options.add(new SelectOption('% vCommit','% vCommit'));
            options.add(new SelectOption('% vOP','% vOP'));
            options.add(new SelectOption('Calls Logged','Calls Logged'));
            
        }
        
        else if(Region == 'KL')
        {       
            options.add(new SelectOption('COA','Coachin'));
            options.add(new SelectOption('MVL','Mavelikara'));
        }
        else
        {
            options.add(new SelectOption('None','--- None ---'));
        }      
        return options;
    }
    
}