PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: akmansoor on December 18, 2008, 01:13:44



Title: How to pass data from different view and pass it to command class
Post by: akmansoor on December 18, 2008, 01:13:44
Hi,

I have three views when I click on a button in one view, it need to pass data from other two views. What is the best way do this. Is there any viewlocater to look for other view datas.

all the views are having its own mediator doing its own thing.



Thanks,
Mansoor Achire


Title: Re: How to pass data from different view and pass it to command class
Post by: puremvc on December 18, 2008, 01:18:01
Then have the mediator for the view with the button send a notification that the other two mediators are interested in. Upon notification, those mediators should that the data exposed to them by their views and send their own notifications carrying the data to be handled by the commands in question.

-=Cliff>


Title: Re: How to pass data from different view and pass it to command class
Post by: akmansoor on December 18, 2008, 01:27:45
Thanks Cliff, Is this the only way?. I was looking for a kind of viewlocatar


Title: Re: How to pass data from different view and pass it to command class
Post by: puremvc on December 18, 2008, 01:40:21
In the scenario I described, you'd have to have 2 commands responding which might not be what you want if you're needing to combine that data somehow in the command.

So, if you want to implement a scheme like the view locator pattern, then simply add methods to your mediators to return the data from their views.

Have the mediator for the button-containing view send a note that triggers a command that retrieves the other 2 mediators, gets the data by calling their methods (not by grabbing and being intimate with their actual view components), and then does whatever it needs to with it.
Note that this builds a coupling between the command and the mediators since the command must know the names of the mediators to retrieve, so it should be done if you can avoid it, but that's why retrieveMediator is there.

-=Cliff>


Title: Re: How to pass data from different view and pass it to command class
Post by: akmansoor on December 18, 2008, 02:16:41
Is it the below approach good.

All the three views will be inside a main view
The Main View Mediator will listen the button click (make event bubbles true)
then the main view will get the data using mainview.chilview.data


Regards,
Mansoor Achire