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

Dynamically Add Component in Page



I have developed different component and I want to add it in visual force pages at runtime. Same like one can add component in Google and myyahoo page.


I don't find any way of doing this. Please help!



David VPDavid VP

Not out of the box.

You might want to create your own framework in VF / Apex to manage this (Don't know if it can be done but at the very least it will be quite a bit of work)


Hi David,


Thanks for reply.  


I have already developed all the component and master page in which I am able to do drag and drop. The only issue is I don't know how to add component at runtime.


i.e. suppose i have 3 component component1,component2 and component3.


I want to add 2 of this in the page at runtime.


If I try to add it using apex:repeat it simply display as text in place of loading the component.


Any help! 

David VPDavid VP

I do not think you can do this at runtime.


What you could do is something like :

Create a page (or another component) that has ALL your components on it, these components have a 'rendered' attribute that's pointing to a set of booleans in your controller (all defaulted to 'false').

Include the page/component where you want the components to appear dynamically and make sure that via your framework you flip the correct boolean(s) to true. That way your components will magically appear or dissapear in your drop target ...


Just an idea.


I've attempted such an implementation and regularly run into the viewstate limit. For some reason even though the rendered attribute is set to false for the components that are not rendered, they are still stored in the viewstate.


It would definitely work as a temporary fix but we need dynamic component binding: