Lazy Mediation of ViewStack

Penut's Avatar


13 Apr, 2011 07:09 PM

I know this subject has been discussed, but no matter what I seem to do, I cannot get my mediation to work.

I'll try to layout my scenario for you.

ParentView: is a container view, that has a toggleButtonBar in the layout, and below that a ViewStack Containing the views A/B/C.

In my parentView Mediator, i have the viewstack set to selectedIndex = 0, as to select ViewA. This has no problem loading and working just fine.

when a button in the bar has been pushed, I capture the event in the ParentView mediator, and change the index of the view stack.
(selectedIndex = 1 etc). It's at this point that my debugger is telling me that the mediator for ViewB cannot reach a label on ViewB, as the view for that mediator is null. I was under the impression the mediation is supposed to happen just after the view has finished being displayed.

All help would be GREATLY appreciated.

my context has the following:

mediatorMap.mapView(parentView, parentViewMediator);
mediatorMap.mapView(ViewA, ViewAMediator);
mediatorMap.mapView(ViewB, ViewBMediator);
mediatorMap.mapView(ViewC, ViewCMediator);

  1. 1 Posted by krasimir on 13 Apr, 2011 07:34 PM

    krasimir's Avatar

    Hi, are you trying to access the "label" in the constructor of ViewB?

  2. 2 Posted by Penut on 13 Apr, 2011 07:38 PM

    Penut's Avatar

    i override the "onRegister" in my mediators, and have a method called "initLabel". that method tries to access the label via the vew. Just everytime it tries, the view associated with the mediator is null.

  3. 3 Posted by krasimir on 13 Apr, 2011 07:40 PM

    krasimir's Avatar

    So you call initLabel in your onRegister method.

  4. 4 Posted by Penut on 13 Apr, 2011 07:44 PM

    Penut's Avatar

    Yes, that is what is happening. I'm only using that to test the changing of the viewstack.

  5. 5 Posted by krasimir on 13 Apr, 2011 07:46 PM

    krasimir's Avatar

    Is it possible to isolate only this part of the application and attach it here. So we can check ;)

  6. 6 Posted by Penut on 13 Apr, 2011 07:49 PM

    Penut's Avatar

    i wish it were possible, however its not. I can build a similar setup when I'm not at my office to post.

  7. 7 Posted by krasimir on 13 Apr, 2011 08:06 PM

    krasimir's Avatar

    I most of the cases isolating the problem in a small app helps a lot. Maybe the problem is not in the view or in the mediator at all.

  8. 8 Posted by Amy Blankenship on 20 Apr, 2011 11:57 PM

    Amy Blankenship's Avatar

    The initialization is a little weird when creationPolicy is auto.

    Personally, I would not have a Mediator reaching into the View that way--the View should be data driven and the Mediator should manipulate its data if necessary. So you might have a thingName property that your View exposes and the label binds to, and your Mediator would set thingName based on whatever you've told it about the application's state.

    If you absolutely HAVE to do this, you can do one of several things

    1. Listen for the initialize event, which shouldn't happen before processedDescriptors is true. Once this has fired, your label should exist.

    2. Use your Mediator to set up a Context on the View, which will map a Mediator to the Label when it hits the stage

    3. Make the label a "marker" subclass, and give it its own Mediator or give it a public property that you can [Inject] into by adding the Label's Class to the ViewMap.

  9. Stray closed this discussion on 11 May, 2011 08:44 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac