Announcement Announcement Module
Collapse
No announcement yet.
Autowired object is null in creationCompleteHandler Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Autowired object is null in creationCompleteHandler

    Hello,

    I wonder if it's possible to access to autowired object in "creationComplete" listener (or initialize). My obect is autowired correctly, but when i try to read it in creationComplete phase, the object is null. I think the autowired has not be done.
    I need to do some job with model and service managed by spring, how can i do that?

    I've developped a simple example to reproduc my issue :

    Code:
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    				layout="horizontal"
    				initialize="{initSpringApplicationContext(event)}">
    	<mx:Script>
    		<![CDATA[
    			import org.springextensions.actionscript.context.support.FlexXMLApplicationContext;
    
    
    			[Embed(source="applicationContextTest.xml", mimeType="application/octet-stream")]
    			public var applicationContextTestFile:Class;
    
    			[Bindable]
    			[Autowired(name='myData')]
    			public var myData:String;
    
    			private function initSpringApplicationContext(event:Event):void
    			{
    				var applicationContext:FlexXMLApplicationContext=new FlexXMLApplicationContext();
    				applicationContext.addEmbeddedConfig(applicationContextTestFile);
    				applicationContext.load();
    				trace("After loading, myData=" + myData);
    			}
    
    			private function labelCreationCompleteHandler(event:Event):void{
    				trace("labelCreationCompleteHandler myData="+myData);
    			}
    		]]>
    	</mx:Script>
    	<mx:Label text="{myData}" creationComplete="{labelCreationCompleteHandler(event)}"/>
    </mx:Application>
    applicationContextTest.xml
    Code:
    	<object id="myData" class="String">
    		<constructor-arg value="SAS"/>
    	</object>

    The label display "SAS" but myData is not yet autowired during creationComplete phase.
    The trace obtains :
    Wed Dec 23 10:48:39 GMT+0100 2009 DEBUG - org.springextensions.actionscript.ioc.factory.xml. XMLObjectFactory - Loading object definitions
    Wed Dec 23 10:48:39 GMT+0100 2009 INFO - org.springextensions.actionscript.ioc.factory.supp ort.DefaultListableObjectFactory - Pre-instantiating singletons in [object FlexXMLApplicationContext]
    After loading, myData=null
    labelCreationCompleteHandler myData=null
    Wed Dec 23 10:48:39 GMT+0100 2009 DEBUG - org.springextensions.actionscript.ioc.wire.Default ObjectDefinitionResolver - Can't find a prototype scoped IObjectDefinition whose type match the object type for TestAutowired0
    Wed Dec 23 10:48:39 GMT+0100 2009 DEBUG - org.springextensions.actionscript.ioc.wire.Default ObjectDefinitionResolver - Using default IObjectDefinition for TestAutowired0
    Wed Dec 23 10:48:40 GMT+0100 2009 DEBUG - org.springextensions.actionscript.ioc.autowire.Def aultAutowireProcessor - Autowiring by name 'TestAutowired.myData' with 'myData'
    Thanks for your help!

  • #2
    Hi,

    the safest way is to create an accessor (getter/setter) for your property instead of a public var and do the logic there so you know it has been set.

    Would that solve your problem?

    regards,
    Christophe

    Comment


    • #3
      Yes that true, i can do that in the setter. It's not a sexy solution but it should work.

      Big thanks for this great actionscript framework, it's very usefull !

      Comment

      Working...
      X