Injecting an object created by OjbectBuilder as a property to view

579 views Asked by At

I have a PresentationModel AS class that holds all the values used in SomeView.mxml. The entire class for the model is bindable, and the model property in the view is also bindable. However, I am unable to inject the model into the view using the PropertyInjector tag:

- INFO: Data binding will not be able to detect assignments to model

Would someone familier with Flex data binding and Mate give me a hand? Thanks a lot!

MainEventMap.mxml

<EventHandlers type="{FlexEvent.INITIALIZE}">
    <ObjectBuilder generator="{PresentationModel}" registerTarget="true">
        <Properties dispatcher="{scope.dispatcher}"/>
    </ObjectBuilder>
</EventHandlers>


<Injectors target="{SomeView}" debug="true">
    <PropertyInjector targetKey="model" source="{PresentationModel}" />
</Injectors> 

Snippet from PresentationModel.as

[Bindable]
public class PresentationModel extends EventDispatcher
{
    public var dispatcher:IEventDispatcher;

    //.....other variables and functions
}

Snippet from SomeView.mxml

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="518" height="562" >
<mx:Script>
    <![CDATA[

         //...... all the imports

        [Bindable]
        public var model:OSGiBrokerConsoleModel;

        // ......other variables and functions
    ]]>
</mx:Script>

    // ..... actual view components

</mx:Canvas>
2

There are 2 answers

0
Glenn On

You cannot bind to a class. Making a class bindable means all members of that class will be bindable, but not the definition itself.

You should create a member function(getter/setter) for the presentation model that returns the data you want to use as the source. Then you also need to create an instance of PresentationModel that you can use for the binding. So rather than binding to PresentationModel.data, you'd bind to myPM.data.

0
Laura On

You can safely ignore that information message.

That message is usually shown when you have a PropetyInjector with source and source key, where the property defined by "sourceKey" is not bindable, so we want to make sure you know that the current value of that property will be the only one the target will ever get (when the property is not bindable, the value is copied and no binding is established). That may or may not be what you want.

In this case, there is no sourceKey, because you don't want to bind to any specific property of the source. Instead, you want to pass the whole PM to the view. Because of that, you don't want to establish a binding, just send the value to the view once.

In the cases where there is no sourceKey or when you are simply sending a one-off value (ie: when you are sending a constant), the message can be ignored.