You need to sign in to do that
Don't have an account?
petermaag
Shared <apex:component> controller context
I have a visualforce page that is composed of several components. I set the controller for each component and the <apex:page> to the same class. I insert one of the instance objects into the database in one of the components. When I try to access the object ID of the object in another component, it is null.
I get the feeling that each component is using a separate instantiation of the controller class. Is this the case? And more importantly, is there a way to allow separate components to share the same controller context?
Thanks.
Yes, you can pass the Page level controller to the Component controller as an Attribute, and then the Component has access to the Page level controller as well as it's own.
theComponent:
<apex:component controller="ComponentController" id="theComponent">
<apex:attribute name="control" type="PageController" assignTo="{!topController}" description="Main page Controller"/>
Component Class:
public class ComponentController {
public PageController topController {get; set;}
....
topController.variable_reference = ... etc.
Page:
...
<c:theComponent control="{!theController}" />
...
Page level Controller:
....
public theController gettheController() {
return this;
}
Hope this helps, Steve.
All Answers
No there is no such way to my knowledge, I would love to see an example if anyone has done such.
Yes, you can pass the Page level controller to the Component controller as an Attribute, and then the Component has access to the Page level controller as well as it's own.
theComponent:
<apex:component controller="ComponentController" id="theComponent">
<apex:attribute name="control" type="PageController" assignTo="{!topController}" description="Main page Controller"/>
Component Class:
public class ComponentController {
public PageController topController {get; set;}
....
topController.variable_reference = ... etc.
Page:
...
<c:theComponent control="{!theController}" />
...
Page level Controller:
....
public theController gettheController() {
return this;
}
Hope this helps, Steve.
That's what I needed. Thanks so much.