Search Here

apex: include Component in Visualforce Page

 The <apex: include> component is another important component in the Visualforce page that is used for inserting a new VF page into the current page. The entire page subtree is injected into the VF DOM at the point of reference, and the scope of the included page is maintained.


Instead of using the <apex: include> component, we use the <apex: composition> component when the content should be stripped from the included page.


The <apex: include> componenthas the following attributes:


1. id

The id is a string type attribute, i.e., a unique identifier that allows the inserted page to be referenced by other components in the page.


Syntax


<apex:include id="cmpId"><apex:include>  

2. pageName

The pageName is an ApexPages.PageReference type attribute, i.e., a VF page whose content needs to be inserted into the current page. The name of the Visualforce page is passed as a value to this attribute.


Syntax


<apex:include pageName="Name of Page"><apex:include>  

3. rendered

The rendered is a Boolean type attribute that is used for specifying whether this component needs to be rendered on the page or not. By default, its value is set to true.


Syntax


<apex:include rendered="true"><apex:include>  

Let's take an example to understand how we can use the <apex: include> component on the Visuaforce page:


ApexImageExample.vfp


<!--create VF page for displaying image -->  

<apex:page showHeader="false">  

    <!--use pageBlock, pageBlockSection an pageBlockSectionItem to display current user information and image -->  

    <apex:pageBlock >  

        <apex:pageBlockSection columns="2">  

            <apex:pageblocksectionitem >  

                {! $User.FirstName } {! $User.LastName }   

                ({! $User.Username })  

            </apex:pageblocksectionitem>  

              

            <apex:pageblocksectionitem >  

                <apex:image url="https://developer.salesforce.com/files/salesforce-developer-network-logo.png"/>  

            </apex:pageblocksectionitem>  

        </apex:pageBlockSection>  

    </apex:pageBlock>  

</apex:page>  

ApexIncludeExample.vfp


<!--apex page start-->  

<apex:page id="thePage">  

    <apex:outputText value="Main Page start"/><br/><br/>  

    <!--use apex:include to add content of ApexImageExample page-->  

    <apex:include pageName="ApexImageExample"/>  

</apex:page>  

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.