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
SFDC_LearnerSFDC_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):
 
 
 
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;}
    }
}
 
 

 

 

Avidev9Avidev9

What do you mean by "Not Rendering properly" ?

 

Did you try puting the second component alone in a page ? Does that render properly ?

Arun MKArun MK

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:

<apex:page >
  <apex:form >
      <apex:outputpanel id="op1">
           <c:VCContacts ></c:VCContacts>
      </apex:outputpanel>
   </apex:form>
</apex:page>

 

 

Component : VCContacts

<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:outputpanel id="op2">
      <apex:actionstatus id="mystatus" startText="loading....">
          <apex:facet name="stop" >
              <c:VCConSelect datavalue="{!selContacts}"></c:VCConSelect>
          </apex:facet>
      </apex:actionstatus>
  </apex:outputpanel>
</apex:component>

 

Component : VCConSelect

<apex:component controller="ContactsDisplayClass">
    <apex:attribute name="datavalue" assignto="{!selContacts}" type="sObject[]" description="Data to pass"/>
    <apex:pageBlock >
          <apex:pageBlockTable value="{!selContacts}" var="sc">
                  <apex:column headerValue="Name" value="{!sc.Name}"/>
          </apex:pageBlockTable>
      </apex:pageBlock>
</apex:component>

 

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.

SFDC_LearnerSFDC_Learner

Thanks for the reply.

 

But in the case of wrapper list what will be the type="" value at <apex:attribute/>

 

 

 <apex:attribute name="datavalue" assignto="{!selContacts}" type="sobject[]" description="Data to pass"/>
    <apex:pageBlock >
          <apex:pageBlockTable value="{!selContacts}" var="sc">
                  <!--
                  <apex:column headerValue="Action">
                      <apex:inputcheckbox value="{!sc.ischecked}"/>
                  </apex:column>
                  -->
                  <apex:column headerValue="Name" value="{!sc.Name}"/> 
          </apex:pageBlockTable>
      </apex:pageBlock>
Tarique ShamimTarique Shamim
Hi SFDC_Learner

In case of wrapper list you can use the Object type for it.
Assuming that selContacts is an object of wrapContactcs.
<apex:attribute name="datavalue" assignto="{!selContacts}" type="Object[]" description="Data to pass"/>
and to use it in the component for fetching the values from it you can hit the values like map.
datavalue['isChecked']; <!-- It will give you the isChecked value-->
datavalue['objC']; <!-- It will give you the Contact object from wrapperClass -->
HTH.
Thanks