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 [2] 3
Print
Author Topic: ViewStacks, Mediators and Deferred Instantiation  (Read 37534 times)
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #15 on: March 10, 2008, 04:05:12 »

Can't really tell, since I don't know what checkForMediator does.

-=Cliff>
Logged
makar
Newbie
*
Posts: 3


View Profile Email
« Reply #16 on: March 11, 2008, 04:04:45 »

the checkForMediator is the same as yours : try to retrieve proxy, and create it if null.
but the problem doesn't come from the method, but from the "activeView" returning null at first time.
it's not binded at the beginning, so we can't instanciate it as you do in your exemple.

it only works if I add a "activeView=viewstack.selectedChild" on the onCreationComplete event.
and if my viewstack.selectedChild contains himself another viewStack, then I have to add a creationComplete event also in my mediator since I can't access directly the children in the constructor.

(there's also the public const GALLERY, etc... that you cast as strings... they might be an int, isn't it?)

thanks,
PiR

« Last Edit: March 11, 2008, 05:40:36 by makar » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #17 on: March 11, 2008, 07:57:33 »

Yes, those strings should be int.

As for your viewstack in a viewstack, I'd simplify the problem by giving each viewstack its own mediator. Then the deferred instantiation problem is easier to deal with.

And why do you not bind activeView?

-=Cliff>
Logged
makar
Newbie
*
Posts: 3


View Profile Email
« Reply #18 on: March 11, 2008, 10:27:41 »

I do bind activeView, but it's not binded at the application startup, (or after the mediator instanciation).

and I actually have a mediator for each viewstack item, but I need to have several viewstacks. it's easier to explain with this:

Main.mxml contains:
    - NavComponent.mxml (linked to mediator)
    - InfoBarComponent.mxml (linked to mediator)
    - a viewStack with (at this time) 2 view items HomeComponent.mxml and MessageBoard.mxml (both linked to related mediators)

HomeComponent.mxml contains:
    - several buttons sending notifications linked to a command, and listened by MainMediator to make the viewStack switch between different views (at this time only messageBoard available)

MessageBoard.mxml contains:
    - a viewStack with 3 items ListMessagesComponent, ReadMessageComponent and WriteMessageComponent (all linked to mediators)


you can then see that when I launch my app, it calls the HomeComponent in the main viewstack. We then select the "message board" button, wich calls the MessageBoard component in the main view stack.
with this, there is no problem with your method.
but if I use your method in chain (so if I call my ListMessageMediator in the MessageBoard constructor), I receive a "null" because flex seems to need a time to show the main viewstack item, and another time to show the message viewstack.


I got my solution adding a onComplete event listener in my ListMessageMediator (and so in other mediators)

do you think on an easier way?

makar

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



View Profile WWW Email
« Reply #19 on: March 11, 2008, 01:55:23 »

Makar,

You're right in handling it with an event sent onCreationComplete for the component in question.

Make that event bubble, and it could be handled by any Mediator attached to any display component up the hierarchy, take your pick.

Usually I have the immediate parent handle it but if there is a lot of depth with this happening at each level, it can be a good idea to have a top-level ApplicationMediator catch the event, and send it to a Command that can do a lookup on the component id or other property and instantiate and register the correct Mediator from an internal hash or switch/case.

-=Cliff>
Logged
phragm3nt
Newbie
*
Posts: 3


View Profile Email
« Reply #20 on: March 24, 2008, 07:26:14 »

Cliff thanks for the great sample code!

I have it about 95% implemented.  What I'm finding is the dynamically instantiated Mediators are not receiving Notifications from my proxy.  Just as I had pulled out my last fistful of hair I registered my MainViewMediator to listen for the notifications and it worked as expected.

Short of posting my code can you guys think of anything I may have missed?

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



View Profile WWW Email
« Reply #21 on: March 25, 2008, 05:00:44 »

You might've forgotten to add the notifications to the array returned from their listNotificationInterests() methods.

If that's not it, I suggest setting a breakpoint on the.line of the Proxy where the missed note is being sent.

Run in debug mode and when it stops at the breakpoint, use the debugger variables view to inspect the facade property. From there you can see everything.

Note you'll need to select 'Show inaccessable member variables' in the Flex menu. That's on the downward pointing triangle widget to the right of the variables view tab in Flex Builder/Eclipse.

Open facade then view, then mediatorMap to see if they're actually there. If so, open observerMap to be sure that, for the notifications in question, there are Observer instances registered pointing to the Mediators in question.

If the above isn't true then you've dropped the ball on getting the Mediators registered before the Proxy sends this notification that's being missed, so move your breakpoint closer to the problem; where the mediator is created and registered.

The debugger is your best friend. Visit it occasionally, it misses you :)

-=Cliff>
Logged
phragm3nt
Newbie
*
Posts: 3


View Profile Email
« Reply #22 on: March 25, 2008, 12:25:56 »

Hey Cliff,

I will give that a shot this evening!  Thanks so much for the ideas!  I do have the interests listed in the array and in the handler with breakpoints!

So I'll dig in with the debugger to see what's going on!

Thanks again,

phragm3nt
Logged
phragm3nt
Newbie
*
Posts: 3


View Profile Email
« Reply #23 on: March 26, 2008, 07:10:56 »

It turns out I neglected to add a call to "checkForMediator" in my Event Handler in the MainViewMediator.

Everything is working great!

Thanks,

phragm3nt
Logged
Gareth Shapiro
Courseware Beta
Newbie
***
Posts: 3


View Profile WWW Email
« Reply #24 on: April 29, 2008, 10:33:24 »

Quick note to say thank you very much Cliff.  I have been working through a lot of the examples on here and have learnt about all I need, to be productive, and hopefully profitable, with Flex and PureMVC.

All thanks to posts like these. 

Thanks once again.

Logged
jinglesthula
Newbie
*
Posts: 8


View Profile Email
« Reply #25 on: June 18, 2008, 02:36:32 »

Yes, the Take 1/Take 2 post was extremely helpful in explaining a few things for me.

Questions:

1. In the checkForMediator function I get a 'possibly undefined method' error on the retrieveMediator call.  The class I'm using it in is MyMediator extends mediator implements IMediator - just like in the example.  I noticed in a search of the forums for 'retrieveMediator' that someone had facade.retrieveMediator, and in the Framework Overview it shows a retrieveMediator method on Facade and View classes, but not the Mediator class.  Is there something different I should do to check for the existence of mediators for views that use deferred instantiation?

2. (this one's minor) I noticed you are using buttons to switch views in the ViewStack in the example and have the mediator code setting the public property currentViewSelector to which the ViewStack's selectedIndex is bound.  I decided to use a TabBar to switch the views in the ViewStack and have the parent component mediator's event handling code simply check for the view mediator and send a notification to the facade for further use.  I have the ViewStack set as the dataProvider for the TabBar and the mediator listens for the ViewStack's change event.  Does this sound right and is the order of events right, or am I violating any idioms or best practices?

Thanks much.
« Last Edit: June 18, 2008, 04:16:02 by jinglesthula » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #26 on: June 20, 2008, 06:24:12 »

1) Use facade. The  code example was in error.

2) Sounds good to me.

-=Cliff>
Logged
neil
Jr. Member
**
Posts: 16


View Profile Email
« Reply #27 on: August 05, 2008, 06:40:46 »

Hi.

I am trying to work my way through this, using Cliff's example code, but I am getting the following error:

1118: Implicit coercion of a value with static type Object to a possibly unrelated type org.puremvc.as3.demos.flex.employeeadmin.view.components:EditorView

The error is pointing to the checkForMediator function:

:
protected function checkForMediator( childSelector:int, child:Object ):void
                {
                        switch (childSelector)
                        {
                             case MainDisplay.PROFILE:
                                  if ( facade.retrieveMediator( ProfileViewMediator.NAME ) == null )
                                     facade.registerMediator(new ProfileViewMediator( child ));
                                  break;
                             case MainDisplay.GALLERY:
                                  if ( facade.retrieveMediator( GalleryViewMediator.NAME ) == null )
                                     facade.registerMediator(new GalleryViewMediator( child ));
                                  break;
                             case MainDisplay.EDITOR:
                                  if ( facade.retrieveMediator( EditorViewMediator.NAME ) == null )
                                     facade.registerMediator(new EditorViewMediator( child ));
                                  break;
                        }
         
                }

I can see that it's to do with the 'child' argument that is passed in, which is taken from mainDisplay.activeView.

Anybody got any ideas?

Thanks,

Neil
Logged
neil
Jr. Member
**
Posts: 16


View Profile Email
« Reply #28 on: August 06, 2008, 07:17:36 »

I've figured out my problem above, but now have something else.

I have a viewstack that triggers the relevant mediator for a view.
However, that view contains other componenets that have their own mediator. Where and how do I call the mediator for this component within a view?

I have tried adding it to the MainDisplyMediator so that when the parent view is called and it's mediator registered, it try's top register the mediator for the component, but how do I pass in the viewComponent?

I have:

:
case MainDisplay.CLIENTS:
 if ( facade.retrieveMediator( ClientViewMediator.NAME ) == null )
 facade.registerMediator(new ClientViewMediator( child ));
 facade.registerMediator(new ClientListMediator( child ));

The child argument refers to ClientView, which is the parent view, but I assume child would need to be ClientList for the second registration.

I hope that makes sense and that someone can help!!

Thanks,

Neil

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



View Profile WWW Email
« Reply #29 on: August 06, 2008, 01:41:48 »

If you register ClientListMediator from within ClientViewMediator, you'll have a reference to the list as an immediate child of the viewComponent ClientView.

-=Cliff>
Logged
Pages: 1 [2] 3
Print