Results 1 to 5 of 5

Thread: Autowiring in Components

  1. #1

    Default Autowiring in Components

    Hi,

    I have some difficulties with SAS and Autowiring in my project.

    I use: Flex 4 Final, Flashbuilder 4 final, SAS 1.0-RC1. My view contains of spark components whereever spark components are available.

    If I try to use Autowiring in my Main.mxml (root application) I can see in the debug that the member variable is autowired.
    But if I try to do so with a component ( Flashbuilder -> New -> Component ) which is somewhere deep in my package structure, no Autowiring is done.

    My basic idea is to use the IOperation pattern to build services which can be easily injected into the PresentationModels.

    What I've done so far:
    used compiler option -keep-as3-metadata += Autowired

    put the defaultAutowiringStageProcessor in my application context
    Code:
    <object id="defaultAutowiringStageProcessor" class="org.springextensions.actionscript.stage.DefaultAutowiringStageProcessor"/>
    defined my PresentationModel in application context
    Code:
    	<object id="userViewPM" class="de.test.presentation.usermanagement.UserViewPresentationModel" depends-on="userService">
    		<property name="userService" ref="userService" />
    	</object>
    defined autowired member variable
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009" 
    		  xmlns:s="library://ns.adobe.com/flex/spark" 
    		  xmlns:mx="library://ns.adobe.com/flex/mx">
    	<fx:Declarations>
    		<!-- Platzieren Sie nichtvisuelle Elemente (z.*B. Dienste, Wertobjekte) hier -->
    	</fx:Declarations>
    	
    	<fx:Script>
    		<![CDATA[
    			
    			[Autowired]
    			[Bindable]
    			public var pm:UserViewPresentationModel;
    						
    		]]>
    	</fx:Script>
    	
    	<s:Group width="100%">
    		
    		<s:Label text="Search" />
    		<s:TextInput id="inputSearch" />
    		<s:Button label="search" click="{pm.findUsers(inputSearch.text)}" />
    		
    		<s:layout>
    			<s:HorizontalLayout />
    		</s:layout>
    		
    	</s:Group>
    	
    	<mx:DataGrid width="100%" height="100%" dataProvider="{pm.userList}">
    		
    		<mx:columns>
    			<mx:DataGridColumn headerText="name" dataField="name" />
    		</mx:columns>
    		
    	</mx:DataGrid>
    	
    </s:VGroup>
    Is my approach totally wrong?

    Regards,
    Christoph

  2. #2
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default IObjectSelector

    Hey Christoph,

    can you post a sample app that demonstrates the problem? I have a vague idea what the problem might be, but I'm not sure so I'd like to examine the code form upclose if that's possible.

    thanks in advance,

    cheers,

    Roland

  3. #3

    Default

    -- removed because it contained rubbish --
    Last edited by flex-guse; Apr 1st, 2010 at 03:14 AM.

  4. #4

    Default

    Hi Roland,

    I found the problem while creating the problem example application

    The problem was when to call the Spring Actionscript method to load the ApplicationContext.

    Example taken from cafe-townsend:
    Code:
    			private function creationCompleteHandler(event:FlexEvent):void {
    				_appContext.addConfigLocation("application-context.xml");
    				_appContext.addEventListener(Event.COMPLETE, handleComplete);
    				_appContext.addEventListener(IOErrorEvent.IO_ERROR, applicationContext_ioErrorHandler);
    				_appContext.load();
    			}
    When I had the Autowiring problems, I called the method in the 'initialisation' phase of my main application.
    If I call the method in the 'creationComplete' phase everything works.
    Code:
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
    			   xmlns:s="library://ns.adobe.com/flex/spark" 
    			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="400" minHeight="300" creationComplete="creationCompleteHandler(event)">
    I should read the examples!

    Thank you for your help,
    Christoph

  5. #5
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    407

    Default great news!

    Hey Christoph,

    great to hear its working for you now! Good luck with your project!
    If you want to be completely on the safe side then call the creationCompleteHandler from the applicationComplete event, that way you can be sure the stage is completely ready.

    cheers,

    Roland

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •