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
gnasagnasa 

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?

 

Thanx.

rohitsfdcrohitsfdc

<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: -->  
    

<apex:page>

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

</apex:page>

            

 <!-- Component:myComponent -->  
    

<apex:component>

    <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}"/> 

    </h1> 

</apex:component>  

 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

bob_buzzardbob_buzzard

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.