tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/537-multiple-views-populating-a-common-display-areaRobotlegs: Discussion 2012-04-11T11:09:40Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/150135862012-04-04T12:52:12Z2012-04-04T12:52:13ZMultiple views populating a common display area<div><p>Hello all,</p>
<p>My application has multiple views (view1, view2, ..) that are
required to populate a common tab navigator (tabnav). To accomplish
this, I create a tabnavModel that holds the tab navigator and
inject it as a singleton.</p>
<p>Each view creates a visual element (datagrid, chart, etc.) that
needs to be added to the common tabnav as a new tab. Here is the
approach I chose: I would need to inject the tabnavModel into each
view mediator. Then, I would need to create the visual elements
inside each view and then pass them in an event (addVisualElement)
to the view mediator. The mediator would then call addElement() to
add the visual element to the common tabnav. My problem is this:
The onRegister method of the viewMediator is where I will register
to listen to the addVisualElement event from the view. For the lack
of a suitable trigger, I create the visual elements inside the
creationCompleteHandler and fire an addVisualElement event.
However, the mediator would not have registered to listen to the
addVisualElement event until after the event is fired because the
creationCompleteHandler in the view runs before the viewMediator's
onRegister method. How do I add my visual elements to the common
display area (tabnav)? Or may be I am on the wrong track and need
to take a different approach. Please let me know what you
think.</p>
<p>Thanks,<br>
c</p></div>Columbustag:robotlegs.tenderapp.com,2009-10-18:Comment/150135862012-04-04T15:38:11Z2012-04-04T15:38:11ZMultiple views populating a common display area<div><p>Hi Columbus,</p>
<blockquote>
<p>However, the mediator would not have registered to listen to the
addVisualElement event until after the event is fired because the
creationCompleteHandler in the view runs before the viewMediator's
onRegister method.</p>
</blockquote>
<p>You have to dispatch your AddVisualElementEvent after the new
visual element has been added to the display list, in order for the
Mediator to hear it.<br>
Just add an event handler for the visual element’s
addedToStage event and dispatch your custom
AddVisualElementEvent.</p>
<p>But I think your approach isn’t quite right, or I
didn’t understand the workflow.<br>
What do you mean by a “common tab navigator
(tabnav)”.<br>
Is it a Flex ViewStack (containing View1, View2, View3) + ButtonBar
?<br>
Is it a mobile app using a ViewNavigator?</p>
<blockquote>
<p>Each view creates a visual element (datagrid, chart, etc.) that
needs to be added to the common tabnav as a new tab.</p>
</blockquote>
<p>Does this mean you have a View2 in a ViewStack or something
similar, and when you navigate to this view, you create a datagrid
and you want to add the datagrid to the ViewStack as well?</p>
<blockquote>
<p>I create a tabnavModel that holds the tab navigator and inject
it as a singleton.</p>
</blockquote>
<p>In my opinion the Model shouldn’t hold a display
object.</p>
<p>I would create a TabNavView paired to a TabNavMediator, and let
the TabNavMediator listen for events from other parts of the app,
and let TabNavView add or remove views.<br>
This way you wouldn’t have to inject the TabnavModel into
your mediators.</p>
<p>But, as I said, I’m afraid I didn’t understand your
use case, so please try and explain again what you need to achieve
:)</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/150135862012-04-09T20:04:45Z2012-04-09T20:04:45ZMultiple views populating a common display area<div><p>Ondina - Thanks for your response. I went with your suggestion
to create a view/mediator for tabnav - which is essentially a
tabnavigator.</p>
<p>c</p></div>Columbustag:robotlegs.tenderapp.com,2009-10-18:Comment/150135862012-04-11T11:01:07Z2012-04-11T11:09:40ZMultiple views populating a common display area<div><p>My pleasure!</p></div>Ondina D.F.