Below code step 1 i have tried with rendering component1 and component2 it is working fine.
step 1:
Visualforce Component1
<apex:component>
<div>
<h1>Component 1 </h1>
</div>
</apex:component>
Visualforce Component2
<apex:component>
<div>
<h1>Component 2 </h1>
</div>
</apex:component>
Visualforce page
<apex:page controller="compcntr2" >
<apex:dynamicComponent componentValue="{!comp1}"/>
<apex:dynamicComponent componentValue="{!comp2}"/>
</apex:page>
Controller:compcntr2
public class compcntr2 {
public Component.c.component1 getComp1(){
Component.c.component1 myCom = new Component.c.component1();
return myCom;
}
public Component.c.component2 getComp2(){
Component.c.component2 myCom = new Component.c.component2();
return myCom;
}
}
output image Below : Header value component 1 and component 2 is displayed.
But the problem is i am facing at Step 2.
Step 2:
Problem is when i try to render same component twice in the same page its not render twice , instead only once it will render. below i have change the visual force page only.
Visualforce page
<apex:page controller="compcntr2" >
<apex:dynamicComponent componentValue="{!comp1}"/>
<apex:dynamicComponent componentValue="{!comp1}"/>
</apex:page>
output image Below :Header value component 1 displayed.
Step 3:
if i extend my question more why i am doing this is because i have planned of generating dynamic component using custom setting. Above code is i add added for understanding what is the problem. actually my code is as follows
Referring this code I have create my below code.
controller
I get two component Name ie.. component1 and component2 from custom setting and assign into comp Map.
public class comcntr {
public list<String> menuList{get;set;}
public integer componentSize{get;set;}
public comcntr() {
Map<String, MyPackagePrefix__componentList__c> comp = MyPackagePrefix__componentList__c.getAll();
menuList=new list<string>(comp.keySet());
system.debug('compName ********' + menuList); //working
componentSize=0;
}
public ApexPages.Component getCustomComponent() {
system.debug('componentName__c ********' + menuList[componentSize]);
MyPackagePrefix__componentList__c comp;
if(componentSize==0){
comp= MyPackagePrefix__componentList__c.getValues(menuList[0]);
system.debug('inside 1 ');
}
else {
comp= MyPackagePrefix__componentList__c.getValues(menuList[1]);
system.debug('inside 2 ');
}
componentSize=1;
system.debug('componentName__c ********' + comp.MyPackagePrefix__componentName__c);
Type reflector = Type.forName(comp.MyPackagePrefix__componentName__c);
IComponentProvider provider = (IComponentProvider)reflector.newInstance();
return provider.provideComponent();
}
}
visualforce Page
<apex:page controller="comcntr">
<apex:repeat value="{!menuList}" var="component">
<apex:dynamicComponent componentValue="{!customComponent}"/>
</apex:repeat>
</apex:page>
i am getting all the value properly, but problem is dynamiceComponent is inside the repeat tag also , Dynamic component never calls customComponent second time. When i check the log file there no trace of second time execution call but still component 1 displayed twice.
Above code display component1 twice, instead of displaying component 1 and component 2.
Can anyone help me why this is happening .