I have multiple visualforce components that each have their own controller that is extended from a base abstract class. For example:
Visualforce Page:
<apex:page>
<c:MyFirstComponent />
<c:MySecondComponent />
...
MyFirstComponent 1:
<apex:component controller="MyFirstComponentController">
MyFirstComponentController Class:
public class MyFirstComponentController extends BaseController {
MySecondComponent 2:
<apex:component controller="MySecondComponentController">
MySecondComponentControllerClass:
public class MySecondComponentController extends BaseController {
BaseController :
public abstract class BaseController {
BaseController(){
getSomeData(); // Here's the problem
}
}
Right now for every component instance on the page a BaseController instance is constructed causing the getSomeData()
method to fire but this is not necessary considering the data is the same for all components on the page. What is the best way to avoid this?
I was thinking perhaps to remove the controller from the components themselves and instead add those controllers as extensions on the page which I would then pass their instance as an attribute to each component... but since each extension extends the BaseController
I would still have duplicates for every component type I have on the page.
Is there a different structure I could use to allow for this without causing these redundancy issues?