Announcement Announcement Module
Collapse
No announcement yet.
Autowiring in Components Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      -- removed because it contained rubbish --
      Last edited by flex-guse; Apr 1st, 2010, 04:14 AM.

      Comment


      • #4
        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

        Comment


        • #5
          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

          Comment

          Working...
          X