+ Start a Discussion
Diana RoslikDiana Roslik 

Add components to the visualforce page dynamically

If there are any options to add components on the visualforce page dynamically?

For example, I have 2 objects (tables). One of them contains components which I need to add to the page (checkbox, list) and the second contains values for this components. 

Actually, it should work like: user open the page, depend on the page, it would contain some general components and also extra components defined in the saleforce object (table). 

Can I make this functionality on visualforce page? If so, could you please provide a link where I can find information how to do this or provide an example?
Scott.MScott.M
There are some components that can be dynamically loaded There are some limitations:

Only standard components (not all of them),
It doesn't work inside of a multi level composition, the dynamic component tag will output nothing

Exmaple from the apex component docs:
<apex:page controller="SimpleDynamicController">
    <apex:dynamicComponent componentValue="{!dynamicDetail}" />
</apex:page>

/* Controller */
public class SimpleDynamicController {

    public Component.Apex.Detail getDynamicDetail() {
        Component.Apex.Detail detail = new Component.Apex.Detail();
        detail.expressions.subject = '{!acct.OwnerId}';
        detail.relatedList = false;
        detail.title = false;
        return detail;
    }

    // Just return the first Account, for example purposes only
    public Account acct {
        get { return [SELECT Id, Name, OwnerId FROM Account LIMIT 1]; }
    }
}


Diana RoslikDiana Roslik
Thanks!