Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Calling Proxy from Mediator...  (Read 14283 times)
seb
Newbie
*
Posts: 8


View Profile Email
« on: February 28, 2009, 04:56:07 »

Hi,

My question is quite simple : I want to call a Proxy directly from the Mediator to initialize a list of data for a Combobox. But is it possible to receive the result without waiting for the Notification thrown by the Proxy?
A kind of synchronous call like :
myList = myProxy.getSomeData();

If not, I will have to register the Mediator for the Notification, but in this case, do all the components that register this Notification receive that Notification even if they are not displayed? If I only want one Mediator to be informed of the result of the Proxy call, is it OK to use the Notification solution?

thanks for your help.

Sebastien
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #1 on: February 28, 2009, 06:27:21 »

Does your proxy itself or the object it controls retrieve the concerned data from a remote server or using any asynchronous call ? If not you can call the proxy exactly as you want with :
:
retrieveProxy("YourProxyName").getSomeData(). It respects MVC, the "view" knows the model and as right to access its data like this.

If the proxy object need to do some asynchronous call behind the proxy magic, you need to use a notification. But only interested mediators will receive the notification that the data has been received. Look at "listNotificationInterests" Mediator method for details.

Logged
seb
Newbie
*
Posts: 8


View Profile Email
« Reply #2 on: March 01, 2009, 12:43:54 »

Thanks for your answer.
Yes, the proxy reads a list of countries in a database throught Java RemoteObject call. So, I understand that I have to use a Notification... no other solution?
And, the next question : in case of a modification of the countries returned (for another continent for example), will all the components registered with the Notification be modified by the new list of countries returned? And if I don't want this, how can I do?

Sebastien
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #3 on: March 01, 2009, 01:13:52 »

If you do not want to use a PureMVC notification, you can use DataBinding. Look at the EmployeeAdmin demo UserVO to understand what I mean. The way it works is the same, but it automatizes the way it creates the notification. My advice is to use a notification.

If you wish to only have the result of the getSomeData() result be taken into account by the mediator that emits the request, you can put a flag property on all interested mediators named for example useImmediatlyNewCountryList:Boolean = false and use something like :

:
{
useImmediatlyNewCountryList = true;
retrieveProxy("YourProxyName").getSomeData()
}

and in the method in charge to receive the notification of a new country list arrived :

:
{
countryList = retrieveProxy("YourProxyName").countryList;
useImmediatlyNewCountryList = false;
}

But there is plenty of other ways to achieve this. You can probably imagine something better in the context of your needs.
« Last Edit: March 01, 2009, 01:16:35 by Tek » Logged
seb
Newbie
*
Posts: 8


View Profile Email
« Reply #4 on: March 01, 2009, 02:01:21 »

OK, I suppose you're talking about DeptEnum from UserVO? I think I understand the use of Enum, but how do I initialize the list of countries from database in the CountryEnum class? Can this class register to be informed for Notifications? Please can you explain me?
Logged
Tekool
Sr. Member
****
Posts: 192


View Profile WWW Email
« Reply #5 on: March 01, 2009, 02:14:00 »

I was talking about UserVo directly because it uses DataBinding. But if you really need to think with a list, you'd better look at RoleVO in the same project. The RoleVO object is Bindable, it uses a Proxy and an ArrayCollection to store the user roles. So when a role is selected or added, the RolePanel reflect the changes immediately without any notification involved in the process. Look at RolePanel roleList List component you'll see what I'm talking about

The model inform the view that data is updated without to have to know any view concrete class, it respects MVC. But you loose control on the notification and will not be able to filter which component must reflect changes or not. You'd better use a notification for that.

« Last Edit: March 01, 2009, 02:15:50 by Tek » Logged
Pages: [1]
Print