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
mike1051mike1051 

Getting value from component class in main class.?

I have shown some fields in my component page and i am using that component in my main page..I want to get the list value that i have used in my component class to my main controller class..I tried to extend my component class and tried to access the list but i am getting a null list..

Component

<apex:component controller="objectComController">
 <apex:repeat value="{!objectList}" var="wra" id="theRepeat">
  <apex:inputField value="{!wra.nameField}"></apex:inputField>
 </apex:repeat>




</apex:component>

Component Class

public with sharing abstract class objectComController{
public List<object__c> objectList{get;set;}

public objectComController()
{
    objectList=new List<object__c>();
}

}

I am getting the values in objectList in this component controller.
Main Class where i have used this controller

public with sharing class mainClass extends objectComController{

   public void Save()
   {
       System.debug('============'+objectList);

   }
}

When i am trying to debug the values of the list in my maincontroller the values are coming null.I just need to get my list values from my component class in my main class.

Its very urgent for me.Please help.Thanks in advance.


Kiran  KurellaKiran Kurella
I am assuming your VF page is referencing mainClass as the controller.  If you want to access the component class in the main controller then you need to pass a reference of the main class to the component as a parameter to avoid re-instantiation of the controller. Here is the pseudo code, where mainClassHandle is passed as a parameter to the component. Hope this will resolve your issue.

// MainClass
public with sharing class mainClass extends objectComController {

	/* HANDLE TO CURRENT INSTANCE OF the controller (to be passed to rendered VF components, avoids re-instantiation of controller) */
	public mainClass mainClassHandle { get {return this;} }

   public void Save() {
       System.debug('============'+objectList);
   }

}

// component
<apex:component >
<apex:attribute name="mainClassHandle" type="mainClass" description="handle to the Main class controller" />

 <apex:repeat value="{!mainClassHandle.objectList}" var="wra" id="theRepeat">
  <apex:inputField value="{!wra.nameField}"></apex:inputField>
 </apex:repeat>

</apex:component>

// virtual class
public with sharing virtual class objectComController {
public List<object__c> objectList{get;set;}

public objectComController() {
    objectList=new List<object__c>();
}

}