+ Start a Discussion

what is difference between including a page and a component.

Hello friends,


I have a doubt about what is the difference between including a page(apex:include) and a component(apex:component).


I mean, when should I use apex:include and when should I use apex:component.


Can any one help me understand this?




<apex:include> is used when you want to insert that page as it is in your current page. The entire contents of that page is copied in your current page.

<apex:component> is defining a component before using it. In simple words, lets  say you define that 'myValue' component is a string type. but the value to that string will be assigned in the destination page.

<!-- Page: -->  


    <c:myComponent myValue="My component's value" borderColor="red" />



 <!-- Component:myComponent -->  


    <apex:attribute name="myValue" description="This is the value for the component." 

        type="String" required="true"/>

    <apex:attribute name="borderColor" description="This is color for the border." 

        type="String" required="true"/>

    <h1 style="border:{!borderColor}">

        <apex:outputText value="{!myValue}"/> 



 in the above example, you are defining attribute name 'Myvalue' as a string type. but the value of this string is assigned in the page. MyValue="My component's value".


Hope this helps you


Also, if you include a page that uses the same controller as the parent page, the same instance of the controller is shared between them.