Suppose I instantiate two sub-objects in Mate event map:
<EventMap>
...
<ObjectBuilder generator="{SubModelA}" />
<ObjectBuilder generator="{SubModelB}" />
...
</EventMap>
...and one main object which must contain previous objects in a collection:
...
<ObjectBuilder generator="{MainModel}" />
...
How can I assign created SubModelA and SubModelB objects as a collection to property in MainModel by using Mate?
You'll have to use the Mate
PropertyInjector
to inject them in an appropriate setter inMainModel
, which handles the collection logic. Something like:Of course, you'll have to add a lot of checks for already added models in the
updateCollection
method. With custom[Bindable]
metadata you'll even support binding to the collection inMainModel
. It is a bit ugly (and, actually, a very bad use of dependency injection), but I'm pretty sure you wouldn't be able to instantiate any collection from the EventMap in a reasonable way. The other way is to create your custom Mate action (it's not that hard, see the sources for hints how to do it). You may also consider simplifying your design.