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
ajithMajithM 

Dynamically display a Component on Visualforce page.

I am trying to create a VF page on which custom components are displayed which are stored in Custom setting or metadata object. So that I can give controll to end user which component they want to see. 

To achieve this I choosed to work with apex:DynamicComponent, I tried different ways but the only i am succesfull when I user {!piechart} for component value. 

<apex:page controller="DashboardCTRL" sidebar="false" >


    
    <apex:repeat value="{!count}" var="i" >
      
        <apex:dynamicComponent componentValue="{!cmps[i]}"/>
      
    </apex:repeat>

*********** or ******************

  <apex:repeat value="{!cmps}" var="cmp" >
      
        <apex:dynamicComponent componentValue="{!cmp}"/>
      
    </apex:repeat>

*************************************

    
</apex:page>


********************* Controller ******************************************

public class DashboardCTRL {

   
    public  ApexPages.Component piechart { get; set; }
    public Map<String,ApexPages.Component> cmps{get;set;}
    
    public List<integer> count{get;set;}

    public DashboardCTRL() {
      cmps = new Map<String, ApexPages.Component>();
      count = new list<integer>();  
    /*    Type t = Type.forName('PieChartCtrl');
        
        System.debug('t is :'+ t);
        
        if(t != null) {
          IComponentProvider cprovider = (IComponentProvider)t.newInstance();
        
        
         nudebt__Dashboard_Settings__c usersettings = nudebt__Dashboard_Settings__c.getInstance(UserInfo.getUserId());
        
       Map<string,Schema.SObjectField> settingFields = Utility.getsObjectFieldMap('nudebt__Dashboard_Settings__c');
        
       List<ApexPages.Component> DashboardList = new List<ApexPages.Component>(); 
        
        integer i = 0; 
        for(string k: settingFields.keySet()){
            
            string fname = settingFields.get(k).getDescribe().getName();
            System.debug('fieldname '+ fname);
            if(fname.startsWith('nudebt__cmp')){
                
                System.debug('component name is'+ usersettings.get(fname));
                
                Type t1 = Type.forName((string)usersettings.get(fname));
        
                System.debug('t is :'+ t1);
        
                if(t1 != null) {
                  IComponentProvider cprovider = (IComponentProvider)t1.newInstance();
                   DashboardList.add(cprovider.provideComponent());
                    this.piechart = cprovider.provideComponent();
                   cmps.put(String.valueOf(i),this.piechart);
                    count.add(i);
                    i++;
                }
            }
        }
    }
    
 
   
}
Ashish DevAshish Dev
Why you did not use "rendered" attribute of vf standard compoenent like panel or pageblok. Upon selection from use control render relavent vf componenent.
ajithMajithM
To make it more dynamic , End user will have capability to subscribe to components we publish. We dont want to change this page everytime we publish a new component.