views:

76

answers:

2

If you once run an ObjectBuilder the object instantiated will be cached and next time you use an PropertyInjector or something else, the instantiated object will be used instead of creating a new object. Or at least this should be like this :)

But in the example below it seems that mate tries to instantiate the object again:

The following error occurs:

! TerminalPresentationModel - constructor called # dispatcher = [object GlobalDispatcher] ! 
<Injectors (started)    target="[class TerminalPresentationModel]"   includeDerivatives="false"   dispatcherType="inherit"   scope="[object Scope]">
        <PropertyInjector   sourceKey="currentDate"   targetKey="date"   source="[class DateManager]"   sourceCache="inherit"   softBinding="false"/>

---------------------------------------------------------
- ERROR: Wrong number of arguments supplied when calling the constructor 
- TARGET: TerminalPresentationModel 
- TAG: PropertyInjector 
- METHOD: constructor
- FILE: TerminalMainEventMap
- NO ARGUMENTS SUPPLIED 
- STACK TRACE: ###SHORTENED###
---------------------------------------------------------


---------------------------------------------------------
- ERROR: source is undefined in tag PropertyInjector 
- TARGET: TerminalPresentationModel 
- TAG: PropertyInjector 
- FILE: TerminalMainEventMap
---------------------------------------------------------

- INFO: Data binding will not be able to detect assignments to date
</Injectors (end)    target=[class TerminalPresentationModel]>
! DateManager - constructor called # dispatcher = [object GlobalDispatcher] !
<Injectors (started)    target="[class TerminalContainer]"   includeDerivatives="false"   dispatcherType="inherit"   scope="[object Scope]">
    <ObjectBuilder   registerTarget="true"   constructorArguments="[object GlobalDispatcher]"   cache="inherit"   generator="[class TerminalPresentationModel]"/>
    <PropertyInjector   targetKey="pm"   source="[object TerminalPresentationModel]"   sourceCache="inherit"   softBinding="false"/>
- INFO: Data binding will not be able to detect assignments to pm
</Injectors (end)    target=[class TerminalContainer]>

Any hints what's wrong with my code?

Update 2010-08-16 As requestes by ktutnik, more details: I use an EventMap:

<?xml version="1.0" encoding="utf-8"?>
<EventMap
    >

    <fx:Script>
        <![CDATA[           
            // imports and namespaces shortened

            [Bindable]
            public var endpoint:String = "";
        ]]>
    </fx:Script>


    <fx:Declarations>
        <Debugger level="{Debugger.ALL}" />

        <myService:Services id="services" endpoint="{endpoint}"/>

        <maps:TimeEventMap endpoint="{endpoint}"/>

        <EventHandlers type="{FlexEvent.PREINITIALIZE}">
            <ObjectBuilder 
                generator="{TerminalPresentationModel}" 
                constructorArguments="{scope.dispatcher}" />
            <ObjectBuilder
                generator="{DateManager}"
                constructorArguments="{scope.dispatcher}" />
            <ObjectBuilder
                generator="{TerminalFaultHandler}" />
        </EventHandlers>

        <EventHandlers type="{DataServiceEvent.GET_CURRENT_TERMINAL_STATUS}">
            <RemoteObjectInvoker instance="{services.TerminalService}"
                 method="getCurrentTerminalStatus"
                 arguments="{[event.locationId,event.actualPlan]}"
                 showBusyCursor="false">
                <resultHandlers>
                    <MethodInvoker generator="{TerminalPresentationModel}"
                                   method="setCurrentTerminalStatus"
                                   arguments="{resultObject}" />
                    <MethodInvoker generator="{TerminalFaultHandler}"
                                   method="removeError" />
                </resultHandlers>
            </RemoteObjectInvoker>
        </EventHandlers>


        <Injectors target="{TerminalContainer}"
                   debug="true">
            <ObjectBuilder
                generator="{TerminalPresentationModel}"
                constructorArguments="{scope.dispatcher}" />
            <PropertyInjector
                targetKey="pm"
                source="{lastReturn}" />
        </Injectors>

        <Injectors target="{TerminalPresentationModel}"
                   debug="true">
            <PropertyInjector targetKey="date" source="{DateManager}" sourceKey="currentDate" />
        </Injectors>

        <Injectors target="{TerminalContent}">
            <PropertyInjector targetKey="faultHandler"
                source="{TerminalFaultHandler}" />
        </Injectors>

        <EventHandlers type="{UnhandledFaultEvent.FAULT}">
            <MethodInvoker generator="{TerminalFaultHandler}" method="handleFault" 
                           arguments="{event.fault}" />
        </EventHandlers>
    </fx:Declarations>
</EventMap>

Flex: 4.0 mate: 0.8.9

A: 

put debug="true" both in your EventHandlers and Injector tag and have a look which one earlier.. try to make combination of CreationComplete event either than PreIntitialize. if im not mistaken in Application CreationComplete is earlier than Preinitialize (but im not realy sure.. because it is confused me too).

ktutnik
The order is: constructor is called (with correct dispatcher) => Injection of date is called => object is built.It is: preinitialize -> initialize -> creationComplete, so change it to creationComplete would probably cause more problems.
hering
Plase complete your code, because many problem can cause this.. ex: EventScoping (EventMap or LocalEventMap) and I don't know if it is DateManager is instantiate correctly or not. **EDIT** if you bring Version of MATE and Version of Flex you use it can help for identify the problem too.
ktutnik
I've added more informations to my question.
hering
A: 

It seems that you can't have two ObjectBuilder in one EventMap. This will cause this issue. As I removed the ObjectBuilder in the Preinitialize-Event everything works fine.

This is a strange behaviour because in other places I wrote it like in this case and no problem occured. So I don't really know WHY it works, but it seems that it fixed my problem.

hering
Yes! actually it is not a problem to have more that one object builder.. what happen if you set `cache="global"` on the objectbuilder which is the child of PreIntialize EventHandler? Anyway I Vote your question, hope Nahuel see this and provide you a direction.
ktutnik
There seems to be no other behaviour if setting cache="global" on the ObjectBuilder.+1 for your help.
hering