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
JarrettKJarrettK 

Component Controllers can they inherit from parent?

Can a custom componenet inheret the controller from the page the controller is embeded in?

Platy ITPlaty IT

I'm not sure if it's best practice or not, but you can pass the page controller into a component as an attribute.  I've done this with extensions, controllers will work the same.  Some snippets of what I've done to accomplish this are below.  In the component controller, I'm then able to access variables and methods from the page controller.

 

Component controller, defining the variable to hold the page extension:
public extRequirementTemplate extRT {get;set;}

Component, attribute to pass that extension from the page to the component:
<apex:attribute name="extRT" assignTo="{!extRT}" description="" type="extRequirementTemplate" required="false"></apex:attribute>

Page controller, define a variable for the controller itself:
public extRequirementTemplate extRT {get;set;}

public extRequirementTemplate(ApexPages.StandardController controller) {
    extRT = this;
}

In the page, pass that variable into the custom component:
<c:RequirementGroup extRT="{!extRT}"/>

 

JarrettKJarrettK

I will try this aproach, sounds logical.

 

Thank you for input!