You need to sign in to do that
Don't have an account?
pcal
Communication between controllers on the same page?
Is there any way for a page controller and custom component controller on a page to find each other and talk to one another?
For complex pages, I'd like to be able to encapsulate different areas of functionality between different components, but still have the ability for the components to pass messages to each other.
For example, consider a page that has a query builder form and a result pane. I'd like to have one component/controller handle a complex UI mechanism for building up a query and another component/controller that handles the retrieval and display of results.
I understand most of how to do this, but I don't see how I can get the components to talk to each other. When the user clicks 'Run Query!' on the query component, I need that controller to take all of the UI inputs, assemble a query string, and then pass that result over to the result component and perform a refresh.
How should I go about achieving something like this in VisualForce? I realize I could do it with one giant page controller that handles everything, but I'm hoping to get a more elegant separation of concerns here (my actual case is a bit more complicated than I describe here).
Thanks much in advance.
-Patrick
For complex pages, I'd like to be able to encapsulate different areas of functionality between different components, but still have the ability for the components to pass messages to each other.
For example, consider a page that has a query builder form and a result pane. I'd like to have one component/controller handle a complex UI mechanism for building up a query and another component/controller that handles the retrieval and display of results.
I understand most of how to do this, but I don't see how I can get the components to talk to each other. When the user clicks 'Run Query!' on the query component, I need that controller to take all of the UI inputs, assemble a query string, and then pass that result over to the result component and perform a refresh.
How should I go about achieving something like this in VisualForce? I realize I could do it with one giant page controller that handles everything, but I'm hoping to get a more elegant separation of concerns here (my actual case is a bit more complicated than I describe here).
Thanks much in advance.
-Patrick
I typically create an apex class to represent the shared state (let's call it SharedState for this example), add a required attribute of type SharedState to the set of components that need to communicate with each other Then I creata a shared state ("data provider") controller extension that has manages the single shared instance of SharedState that I can mix into any controller.
Message Edited by dchasman on 08-02-2008 10:14 AM
And the component registers itself as a listener on the shared class:
The shared component can then fire off events that can communicate between page / component:
Right, I was hoping that there was some kind of injection mechanism - for some reason it just never occurred to me to pass my own objects in via attributes. I implemented this in my code yesterday - separate component controllers listening to each other, wired up by the page controller - everything works great.
The only thing I might wish for is the ability to actually inject the controller instance that a given component uses. As it is, my <apex:components> skip the controller attribute entirely and instead just get their 'controller' via an 'injectedController' attribute. Not a big deal except that I have to qualify references everywhere in the component definition ({!injectedController.foo})...
Anyway, that's a quibble - things are working very nicely now. Thanks for setting me on the right track.
Cheers,
-p
leads to being able to use {!foo.bar}