+ Start a Discussion
mayank_friend52mayank_friend52 

Can we call one Apex:Component inside the other Apex:Component

Hello,

Can we call one Apex:Component inside the other Apex:Component?

Please suggest some ways to accomplish this.


Thanks,
Mayank
Peter_sfdcPeter_sfdc
Don't see why not. As long as the content of the one component is allowed as a child of the other component, this should work.

Something like:
Inner Component named: inner
<apex:component>

   ...blah blah blah...

</apex:component>
Then you have the outer one:
Outer Component named: outer
<apex:component>

    ...blah blah blah...

    <c:inner/>

</apex:component>
Then in your page:
<apex:page>

    <c:outer/>

</apex:page>
Should be as basic as that.

(Incidentally, this post really should go in the Visualforce topic...despite the "apex" namespace, visualforce isn't Apex.)
mayank_friend52mayank_friend52
Hello Peter,

Thanks for the quick response.
It works.
But can you suggest me a way to send some value from page to component while on page load.

Thanks,
Mayank
Peter_sfdcPeter_sfdc
There are several different ways. It would help to answer your question if you could be more specific as to what exactly you need to accomplish. What is the business case? Why are you choosing this architecture? What have you tried already that has not succeeded? 

If you just need a hand getting started with passing values between pages and components, I would suggest looking at the Visualforce developer guide. Or working through the Visualforce workbook. 
mayank_friend52mayank_friend52

Hello Peter,

Thanks for the reply.

Exact Business Scenario:

I have a code which is to be use in many pages,the only difference is the parameter to be pass from every page, like an user id, so rather writing them in every page, I would like to use component for that and reuse that component in every page.

Please tell me , is that possible to achieve this.

Thanks,

Mayank

Peter_sfdcPeter_sfdc
I would suggest taking at look at this page in the Visualforce Developer Guide as a first step to understanding this. 

Have a go. 

If you have troubles, certainly check back: 
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_comp_cust_elements_markup.htm