You need to sign in to do that
Don't have an account?
Enrico dev
Pass VF component attribute to component extension
Following is my code:
VF PAGE:
VF COMPONENT used in above page:
COMPONENT CUSTOM CONTROLLER:
COMPONENT EXTENSION CONTROLLER:
I know that we cannot access the attribute record_Id in the constructor of the VF component controller (null value) so i m setting it with
public void setrecord_Id(id s){
How can i pass record_Id to the component extension controller ? I mean to ForecastHierarchyEditCompExtension constructor.
I would like to get populate myReference.acc or myReference.record_Id so that also List ForecastCustomers will be populated.
Actually List is not populated because acct is null.
Thanks in advantage for any advice.
VF PAGE:
<apex:page standardController="account" extensions="ForecastHierarchyEditExtension" tabStyle="Account" sidebar="false" standardStylesheets="false"> <c:ForecastHierarchyEdit recordId="{!account.id}"/> </apex:page>
VF COMPONENT used in above page:
<apex:component Controller="ForecastHierarchyController" extensions="ForecastHierarchyEditCompExtension"> <apex:attribute name="recordId" description="Record Id" type="id" assignTo="{!record_Id}" required="true"/> <apex:form > <apex:selectList value="{!ForecastCustomerToDelete}" multiselect="false"> <apex:selectOptions value="{!ForecastCustomers}"/> </apex:selectList> </apex:form> </apex:component>
COMPONENT CUSTOM CONTROLLER:
public class ForecastHierarchyController { public account acc{get;set;} public id record_Id; public id getrecord_Id(){ return record_Id; } //Following is the solution for record_Id null in the constructor public void setrecord_Id(id s){ if (s!=null){ record_Id = s; GetData(); } } public ForecastHierarchyController() { /*Since the constructor is called before the setter record_Id will always be null when the constructor is called.*/ system.debug('record_Id '+record_Id); } public void GetData(){ acc=[select Id from account where id=:record_Id]; system.debug('Component Controller acct '+acc); } }
COMPONENT EXTENSION CONTROLLER:
public class ForecastHierarchyEditCompExtension { public id ForecastCustomerToDelete { get; set; } private final ForecastHierarchyController myReference; private final Account acct; public ForecastHierarchyEditCompExtension (ForecastHierarchyController ForecastHierarchyCtrl) { this.myReference = ForecastHierarchyCtrl; System.debug('myReference: ' + myReference); acct=myReference.acc; } public List<SelectOption> ForecastCustomers{ get { List<SelectOption> ForecastCustomers = new List<SelectOption>(); //here acct=null system.debug('Component Controller Extension acct '+acct); if (acct!=null){ if (acct.id!=null){ for (account acc :[select id,Name from account where Forecast_Account__c=: acct.id]){ ForecastCustomers.add( new SelectOption( acc.id, acc.Name ) ); } } } return ForecastCustomers; } private set; } }
I know that we cannot access the attribute record_Id in the constructor of the VF component controller (null value) so i m setting it with
public void setrecord_Id(id s){
How can i pass record_Id to the component extension controller ? I mean to ForecastHierarchyEditCompExtension constructor.
I would like to get populate myReference.acc or myReference.record_Id so that also List ForecastCustomers will be populated.
Actually List is not populated because acct is null.
Thanks in advantage for any advice.
Try creating an other varaible in extension controller and pass the account id to it too! like:
Extension:
Hope it helps:
Thanks,
balaji
Use "static" concept:
ForecastHierarchyController:
...
public Static record_Id{get;set;}
and in extension controller refer it as:
..........
for (account acc :[select id,Name from account whereForecast_Account__c=:ForecastHierarchyController.record_Id]){
......................
Try it!
Thanks,
Balaji