Creating child views dynamically and adding to parent view

kamcknig's Avatar

kamcknig

22 Nov, 2011 08:15 PM

Hi Everyone!

I have a problem. I have a ParentView that has a mediator. In the ParentView I want to create an arbitrary number of ChildViews. But the problem is that the ChildViews have injections in them that need to be respected. But I can't create those children in the ParentView using the new constructor because then the injections in the children don't get triggered. So I thought about creating the ChildViews in the ParentView's mediator but the mediator doesn't have access to the injector to create the objects.

What is the best practice for this??

Kyle

  1. 1 Posted by kamcknig on 22 Nov, 2011 08:41 PM

    kamcknig's Avatar

    The only way I can really think is to dispatch an event from the view that is caught and triggers a command to create the views and then dispatch out another event with those views as a payload and have the mediator on the parent view tell it's mediated view to add those new child views to its display list. But that feels cumbersome to me.

  2. 2 Posted by kamcknig on 22 Nov, 2011 08:48 PM

    kamcknig's Avatar

    Or maybe I can create a ChildViewFactory with a reference to the injector? And then inject the factory into the ParentView and have the ParentView use the factor to create the children?

    Sorry, I'm new to RobotLegs and trying to figure it all out.

    Kyle

  3. 3 Posted by Stray on 22 Nov, 2011 10:33 PM

    Stray's Avatar

    Hi Kyle - sorry for the delay. yes - a factory that you inject into the parent view would be a good solution.

    Don't forget that you can do 'manual DI' - so you could inject that factory into the parent view's mediator and pass it to the parent view, for example.

    Let us know if you need any more pointers,

    Stray

  4. 4 Posted by kamcknig on 23 Nov, 2011 01:39 AM

    kamcknig's Avatar

    No worries! I was just working through it in my head and it helps to write it out :)

    Thanks!

  5. kamcknig closed this discussion on 23 Nov, 2011 01:40 AM.

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

Keyboard shortcuts

Generic

? 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