You need to sign in to do that
Don't have an account?
SFDC_Learner
Rendering Problem with Components
Hi,
I dont know whether it is possible or not.
I have two components and a page.
I am using components in a page and rendering the second component.
But the second component is not rendering properly.
Any Idea!
VF Page Code:
<apex:page >
<apex:form >
<apex:outputpanel id="op1">
<c:VCContacts ></c:VCContacts>
</apex:outputpanel>
<apex:outputpanel id="op2">
<apex:actionstatus id="mystatus" startText="loading....">
<apex:facet name="stop" >
<c:VCConSelect ></c:VCConSelect>
</apex:facet>
</apex:actionstatus>
</apex:outputpanel>
</apex:form>
</apex:page>
********************************
Component1 (VCContacts):
Query String : https://c.ap1.visual.force.com/apexcomponent/VCContacts?id=<AccountID>
Code:
<apex:component controller="ContactsDisplayClass">
<apex:pageBlock >
<apex:pageBlockTable value="{!lstWC}" var="wc">
<apex:column headerValue="Action">
<apex:inputcheckbox value="{!wc.ischecked}"/>
</apex:column>
<apex:column headerValue="Name" value="{!wc.objC.name}"/>
</apex:pageBlockTable>
<apex:commandButton value="ShowSelected" action="{!doShow}" reRender="op2" status="mystatus"/>
</apex:pageBlock>
</apex:component>
*******************************
Component2 (VCConSelect)
Code:
<apex:component controller="ContactsDisplayClass">
<apex:pageBlock >
<apex:pageBlockTable value="{!selContacts}" var="sc">
<apex:column headerValue="Name" value="{!sc.Name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:component>
*******************
Common Controller for both Components:
Controller code:
public with sharing class ContactsDisplayClass {
public List<String> conIds = new List<String>();
public void doShow() {
for(wrapContactcs objWC : lstWC){
if(objWC.ischecked == true){
conIds.add(objWC.objC.Id);
}
}
selContacts = new List<contact>();
selContacts = [select id,name from Contact where ID IN : conIds];
system.debug('--selContacts are -->'+selContacts);
}
public List<Contact> selContacts{get;set;}
public List<Contact> lstC{get;set;}
public List<wrapContactcs> lstWC{get;set;}
public ContactsDisplayClass(){
lstC = new List<Contact>();
lstC = [select id,name,AccountId from Contact where AccountId =: apexPages.currentpage().getParameters().get('id')];
lstWC = new List<wrapContactcs>();
for(Contact objC : lstC){
wrapContactcs objWC = new wrapContactcs();
objWC.objC = objC;
lstWC.add(objWC);
}
}
public class wrapContactcs{
public boolean ischecked{get;set;}
public Contact objC{get;set;}
}
}
What do you mean by "Not Rendering properly" ?
Did you try puting the second component alone in a page ? Does that render properly ?
Hi,
You cannot share the same instant of controller between two components.
Instead you can try to pass the List of Contacts from one component to another component.
Try the following code.
No change is required for the controller.
VF Page:
Component : VCContacts
Component : VCConSelect
This worked fine in my dev org. Try this and let me know if it is not working.
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Regards,
Arun.
Thanks for the reply.
But in the case of wrapper list what will be the type="" value at <apex:attribute/>
In case of wrapper list you can use the Object type for it.
Assuming that selContacts is an object of wrapContactcs. and to use it in the component for fetching the values from it you can hit the values like map. HTH.
Thanks