Results 1 to 9 of 9

Thread: MVCRouteEventsMetaDataProcessor problem with non-Flex project

  1. #1
    Join Date
    Feb 2011
    Location
    Milan
    Posts
    7

    Default MVCRouteEventsMetaDataProcessor problem with non-Flex project

    Hi,
    i tried to develop a simple application using MVC micro-framework in pure as3 project.

    The most important question is...
    Can i use MVC micro-framework in a pure as3 Project?

    if no...DOH ,else

    I've some troubles when i use [RouteMVCEvents] metatag.
    in my case,
    when MVCRouteEventsMetaDataProcessor.rerouteToEventBus( ) method is called, the owner variable is null


    This is what happens:

    compiler arguments i used are:

    -keep-as3-metadata+=Autowired
    -keep-as3-metadata+=EventHandler
    -keep-as3-metadata+=RouteEvents

    I tried 2 different kind of DefaultAutowiringStageProcessor definition

    The first one is:
    Code:
    <object id="autowiringStageProcessor" class="org.springextensions.actionscript.stage.DefaultAutowiringStageProcessor"/>
    Main.as
    Code:
    [RouteMVCEvents]
    [Event(name="startupEvent",type="command.control.StartupEvent")]
    public class Main extends Sprite {
    	private var context : XMLApplicationContext;
    	{		
            StartupCommand;
            MVCControllerObjectFactoryPostProcessor;
    	DefaultAutowiringStageProcessor;		
    	FlexStageDefaultObjectSelector;
    
    	}
    	public function Main() {
    		FlashStageProcessorRegistry.getInstance().stage = stage;
    		context = new XMLApplicationContext("application-context.xml");
    		context.addEventListener(Event.COMPLETE, handleComplete_CONTEXT);
    		context.load();
    			
    	}
    
    	private function handleComplete_CONTEXT(ev : Event) : void {
    		context.removeEventListener(Event.COMPLETE, handleComplete_CONTEXT);
    		var cgEvent : StartupEvent = new StartupEvent();
    		dispatchEvent(cgEvent);
    	}
    }
    I omited the StartupCommand, but there is [Command(eventType="startupEvent")] metatag

    Result: the Dispatched Event do nothing and in log1.txt is the log

    The second one is:
    Code:
     <object id="autowiringStageProcessor"
            class="org.springextensions.actionscript.stage.DefaultAutowiringStageProcessor">
            <property name="objectSelector">
                <object class="stage.CustomObjectSelector"/>
            </property>
    and in the Main.as i added
    Code:
    {
    	StartupCommand;	
    	MVCControllerObjectFactoryPostProcessor;
    	DefaultAutowiringStageProcessor;
    	CustomObjectSelector;
    	FlexStageDefaultObjectSelector;
    	
    }
    Results:
    the owner variable in MVCRouteEventsMetaDataProcessor/rerouteToEventBus() is null and so when it try to create a new MVCEvent, the required parameter is null and throw an error.

    Thanks a lot
    Marco
    Attached Files Attached Files

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

    Default trunk

    Hey there,

    are you using the 1.1 drop? If so, can you try compiling from the SVN trunk? I seem to recall fixing a bug concerning the owner property just last week.
    If you have problems creating your own build drop me a PM and I'll email you a swc.
    If you are using Maven then simply add a dependency to the 1.2-SNAPSHOT and you should have the latest build.

    cheers,

    Roland

  3. #3
    Join Date
    Feb 2011
    Location
    Milan
    Posts
    7

    Default

    Hi,
    as you said in SAS 1.1 owner variable is null and so throw an error.

    My bad solution is to dispatch MVCEvent directly

    Code:
    EventBus.dispatchEvent(new MVCEvent(null, cgEvent));
    I know it's not a solution but a trick, but my goal was to understand


    About SAS 1.2 (i think) i used svn source but i'm not sure i did the right workflow,because i need to add

    as3commons-eventbus-1.1.1 to import IEventBusAware interface

    and

    as3commons Collections 1.1 to import WeakLinkedList class


    well...

    i tried to compile SWC with FDT 4, flex Hero SDK

    but i don't know all the metatags that I need to "keep"

    reading this post I found a list of metatags, that I CUT&PASTE, but nothing happens :P

    Is there a little tutorial on which METATAGS are necessary or how to compile SAS SWC?, so that any updates on svn source can be accessible


    Thanks a lot.

    P.S.
    I love this framework. i'm self-taught developer and when i read about this project i learned a lot of new concepts...
    GREAT PROJECT
    Last edited by marcaia; Apr 5th, 2011 at 10:05 AM. Reason: updated the post

  4. #4
    Join Date
    Feb 2011
    Location
    Milan
    Posts
    7

    Default SAS 1.2 wraps Event in MVCEvent in non-Flex project.

    Hi,
    I used Intellij IDEA Maven plugin to build SAS 1.2.
    This was my first time so i think i forget some metatag somewhere

    The good news is that SAS 1.2 wraps Event in MVCEvent in non-Flex project.



    this is the piece of LOG trace
    Code:
    21:35:8.896 DEBUG - FlashStageProcessorRegistry - Stage processing completed
    21:35:8.896 DEBUG - FlashStageProcessorRegistry - FlashStageProcessorRegistry was initialized
    21:35:8.898 DEBUG - EventBus - Notified eventbus listener [object EventBusAdapter] of event [MVCEvent(document=[null], event=[Event type="startupEvent" bubbles=false cancelable=false eventPhase=2], bubbles=false, cancelable=false)]
    21:35:8.898 DEBUG - EventBus - Notified eventbus listener [object AS3CommonsEventBusListener] of event [MVCEvent(document=[null], event=[Event type="startupEvent" bubbles=false cancelable=false eventPhase=2], bubbles=false, cancelable=false)] for topic null
    Next step is to understand why StartupCommand can't handle the event.
    I can bet on a Metatag missing

    I think so, because when i compile my example with MXML, FlexXMLApplicationContext and SAS 1.1 everythings works fine, but when I compile my example with MXML, FlexXMLApplicationContext and SAS 1.2, the "trace" is not shown.



    Main.as
    Code:
    [RouteMVCEvents]
    [Event(name="startupEvent",type="command.control.StartupEvent")]
    StartupCommand.as

    Code:
    [Command(eventType="startupEvent")]
    	public class StartupCommand {
    		public function execute(event : StartupEvent) : void {
    			trace("startupCommand.execute");
    			
    		}
    	}
    and application-context.xml

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <objects xmlns="http://www.springactionscript.org/schema/objects"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springactionscript.org/schema/objects
    					http://www.springactionscript.org/schema/objects/spring-actionscript-objects-1.0.xsd">
    
    	<object id="eventhandlerProcessor"
    		class="org.springextensions.actionscript.ioc.factory.config.EventHandlerMetadataProcessor" />
    	<object id="autowiringStageProcessor"
    		class="org.springextensions.actionscript.stage.DefaultAutowiringStageProcessor">
    		<property name="objectSelector">
    			<object class="stage.CustomObjectSelector" />
    		</property>
    	</object>
    
    	<object id="mvcFactory"
    		class="org.springextensions.actionscript.core.mvc.MVCControllerObjectFactoryPostProcessor" />
    
    	<object id="startupCommand" class="command.StartupCommand"
    		scope="prototype" />
    </objects>

  5. #5
    Join Date
    Sep 2010
    Posts
    1

    Default

    Quote Originally Posted by marcaia View Post
    Hi,
    ...
    I've some troubles when i use [RouteMVCEvents] metatag.
    ...
    -keep-as3-metadata+=RouteEvents
    ...
    Main.as
    Code:
    [RouteMVCEvents]
    [Event(name="startupEvent",type="command.control.StartupEvent")]
    public class Main extends Sprite {
    ...
    RouteEvents != RouteMVCEvents

  6. #6
    Join Date
    Feb 2011
    Location
    Milan
    Posts
    7

    Default metatag in pom.xml

    probably my bad English doesn't help


    Looking around, i read that SWC keep METADATA.
    in SAS 1.1 a list of metatags to keep is defined in pom.xml.

    i found this
    Code:
     <keepAs3Metadatas>
    <param>Autowired</param>
                            <param>Inject</param>
    			<param>Command</param>
    			<param>Component</param>
    			<param>Constructor</param>
    			<param>Event</param>
    			<param>EventHandler</param>
    			<param>Property</param>
    			<param>Invoke</param>
    			<param>PostConstruct</param>
    			<param>PreDestroy</param>
    			<param>Required</param>
    			<param>RouteEvents</param>
    			<param>RouteMVCEvents</param>
    </keepAs3Metadatas>
    so these metatags are included. In fact I delete compiler arguments "-keep-as3-metadata" and the MVC example works fine.

    At the moment, my troubles is listen to dispatched event with SAS 1.2

    I built spring-actionscript-core-1.2-SNAPSHOT.swc with Maven plugin in Intellij IDEA

    metadata [RouteMVCEvents] is registered

    Code:
    18:27:29.301 DEBUG - MetadataProcessorObjectPostProcessor - Registered metadata '[RouteMVCEvents]' with processor '[object MVCRouteEventsMetaDataProcessor]'

    Singleton StartupCommand is registered for event
    Code:
    18:27:29.355 DEBUG - Controller - command startupCommand registered for event type startupEvent with execute method execute and priority 0
    metadata [Event] found for event

    Code:
    18:27:29.605 DEBUG - MVCRouteEventsMetaDataProcessor - Found [Event] metadata for event startupEvent
    18:27:29.611 DEBUG - MVCRouteEventsMetaDataProcessor - added listener for event type 'startupEvent' on [object Main]
    event is dispatched

    Code:
    18:31:53.865 DEBUG - EventBus - Notified eventbus listener [object AS3CommonsEventBusListener] of event [MVCEvent(document=[null], event=[Event type="startupEvent" bubbles=false cancelable=false eventPhase=2], bubbles=false, cancelable=false)] for topic null
    18:31:53.865 DEBUG - EventBus - Notified eventbus listener [object EventBusAdapter] of event [MVCEvent(document=[null], event=[Event type="startupEvent" bubbles=false cancelable=false eventPhase=2], bubbles=false, cancelable=false)]
    but trace in StartupCommand execute method is not shown...
    Last edited by marcaia; Apr 6th, 2011 at 02:00 PM. Reason: spelling error

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

    Default sample

    Hey there,

    I'm sorry to hear you're still having issues with the MVC system. I do believe you're very close to having things working though. This might be a last bug in SpringAS.
    Therefore I'd like to ask you if it might be possible for you to post a small sample application here that demonstrates your problem. In that case I can investigate a little easier what's going wrong and might be able to fix the problem.

    Thank you very much in advance,

    cheers,

    Roland

  8. #8
    Join Date
    Feb 2011
    Location
    Milan
    Posts
    7

    Default sample

    Hi Roland,

    I did a sample with SAS 1.1 and SAS 1.2 .
    I omited SWCS for file-size reasons. There is a screenshot too

    n.b.
    Spring Actionscript - Framework Source.swc is the SAS 1.2 built with FDT

    thanks for your availability
    Marco

    I was reading the code, is it possible that eventBus is not assigned to Controller? and when framework checks if dispatching through eventbus it skips?or it's a nonsense

    in MVCControllerObjectFactoryPostProcessor class i added this line and it works, but I'm not sure it is just a trick

    Code:
    public function addMVControllerInstance(objectFactory:IConfigurableListableObjectFactory):IController {
    			Assert.notNull(objectFactory, "the objectFactory argument must not be null");
    			var names:Array = objectFactory.getObjectNamesForType(IController);
    			if (names.length < 1) {
    				var controller:Controller = objectFactory.createInstance(Controller);
    				controller.eventBus=objectFactory.eventBus;
    				objectFactory.registerSingleton(CONTROLLER_OBJECT_NAME, controller);
    				return controller;
    			} else {
    				return objectFactory.getObject(String(names[0]));
    			}
    		}
    Attached Files Attached Files
    Last edited by marcaia; Apr 7th, 2011 at 10:50 AM. Reason: updates

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

    Default good catch!

    Hey Marco,

    I think you are right actually, the eventbus doesn't get assigned automatically yet to the controller. This is something I need to build into the spring container still. Your fix is indeed valid, good catch!

    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
  •