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: Blank notification returned to Mediator  (Read 11123 times)
aliali
Newbie
*
Posts: 4


View Profile Email
« on: August 18, 2009, 03:45:54 »

Hi there, thanks for checking my post. I've read through the best practice and other introductory documents and have completed a couple of AS3/Flex tutorials so this is my first attempt at building a puremvc app from the ground up. I guess I've missed something obvious but if someone could take time to let me know what that obvious thing is I would be really grateful!

I'm building a simple app that populates a combo box with a list of drinks and then stores the order in a proxy.

My problem is that when my DrinksListProxy sends a notification (to populate the combo box where you select a drink) it is received by my DrinkComboMediator but the notification is blank (flex traces org.puremvc.as3.patterns.observer.Notification (@222254e9)). I've put breakpoints in my code to check the notification is generated correctly and the body and name seem to be set but when my handleNotification method is reached, I get the blank notification. Here's my code from DrinkComboMediator:
:
override public function listNotificationInterests():Array
{
var retA:Array = [
ApplicationFacade.DRINKS_LIST_RECEIVED

];
return retA;
}

override public function handleNotification(notification:INotification):void
{
//blank notification received here!
var drinksListProxy:DrinksListProxy = facade.retrieveProxy(DrinksListProxy.NAME) as DrinksListProxy;
switch ( notification.getName() )
{
case ApplicationFacade.DRINKS_LIST_RECEIVED:
//set data provider  TODO target the drinks combo correctly
viewComponent.drinksCombo.dataProvider = notification.getBody() as ArrayCollection;
break
default : break;
}

}

You can download the source from here:
http://dl.getdropbox.com/u/65140/DrinkTouchLight.zip


My second problem (which is more flex related than puremvc) is that I can't target my drinksCombo mxml component from my DrinksMediator class. This is the view component that contains the combo box. Again I think I've made a pretty basic error here but if someone could point it out I'd be really grateful.

If anyone could assist it would be a massive help as I'm really enjoying working with puremvc but I've hit an obstacle I can't seem to get over.

Thanks in advance,
Ali



Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: August 20, 2009, 07:16:05 »

Don't know where you're dropping the ball on the notification body, but I can say the notification system works and if you breakpoint in your proxy and step all the way through until you are inside handleNotification, you're bound to see where it falls through the cracks.

As for getting the data into the combo box, you don't want do it this way. You're breaking the encapsulation of the view component. If the view component changes its implementation from a combo box to a data grid or some such, then you have to refactor the mediator because it knew too much.

Instead have the view component expose a 'drinks' property. Have the mediator set the view component's drinks property. Then inside the view component, bind the dataprovider of the combo to that property. Now the mediator only needs to know about a top level property and not about the black box implementation of its view component.

-=Cliff>
Logged
aliali
Newbie
*
Posts: 4


View Profile Email
« Reply #2 on: August 24, 2009, 02:21:24 »

Hi Cliff, thanks for responding to my question and also for the advice on breaking the encapsulation, that completely makes sense. I'm going to step through all of my code to see where the notification is getting lost now.
Thanks for taking the time out to respond, and thanks for such a great framework!
Ali
Logged
aliali
Newbie
*
Posts: 4


View Profile Email
« Reply #3 on: August 24, 2009, 04:48:23 »

I have everything working now so thought I'd write my findings:

My blank notification problem was that I was trying to debug the properties of INotification as it entered handleNotification() which made me think it was blank when in fact it wasn't. As the properties (body and name) aren't exposed I wasn't getting anything until I called these methods and the Flex debugger wouldn't let me drill down into the properties.

I've set a drinks ArrayCollection property in the view component that the view mediator updates so now I have encapsulation here, thanks!

My final problem with accessing the view component was solved by calling notifyObservers() in the facade, triggered by the applicationComplete event which also passes a reference to the Application. This then registers the ApplicationMediator and also passes it a ref to the Application which it in turn passes onto it's children view components.

All of this is pretty basic stuff, I hope it makes sense and may be useful to someone.
Thanks
Ali

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: August 26, 2009, 12:58:48 »

In order to view those protected properties in the Flex Builder debugger perspective, look at the view with tabs named 'Variables', 'Breakpoints', 'Expressions', then let your eye travel to the right side of that view. There are several icons there, and you're looking for a downward pointing triangle. Click it and the menu that opens should have an item called 'Flex', click that and you should see 'Show inaccessible members'. Check that option and you'll be able to see everything.

-=Cliff>
Logged
aliali
Newbie
*
Posts: 4


View Profile Email
« Reply #5 on: August 26, 2009, 03:03:16 »

I didn't know that option existed! I can see the inaccessible properties now.
Thanks for letting me know :)
Ali

Logged
Pages: [1]
Print