Passing Event payload to Command
With reference to the following discussion: http://knowledge.robotlegs.org/discussions/robotlegs-2/15290-mapping-event-with-second-type-to-command-is-not-working
I am passing Event with Payload and mapping it to Command in the Context, but for some reason the payload does not arrive at my Command. I am injecting the Event into the Command:
public var fileLoadedEvent:FileLoadedEvent;
override public function execute():void
var xmlFile:XML = fileLoadedEvent.file;
The event is fired from a service that loads a XML file from the host filesystem. When I put breakpoints in the service and/or event, the payload does show in the Variables windows (FlashBuilder Debug), but when it executes above assignment, then it bombs out, because payload is not present.
Comments are currently closed for this discussion. You can start a new one.
|?||Show this help|
|ESC||Blurs the current field|
|r||Focus the comment reply box|
|^ + ↩||Submit the comment|
You can use
Command ⌘ instead of
Control ^ on Mac
Support Staff 1 Posted by Ondina D.F. on 18 Sep, 2016 08:15 AM
[INJECT] should be [Inject]
Take a look at the 2 most common problems pertaining to metadata:
Look at how the eventCommandMap works and how to map your events to a command:
In robotlegs 2 you don't need to extend a command class. Any class having a public method execute() and mapped correctly to an event will be recognized by the framework as being a Command.
I gave you an example of an Event class and a Command class in one of our previous discussions:
Hier a modified version with an injected event:
If none of the above solves your problem, I'll need to see:
Have you tried to send another type of payload to the command, say, a simple String instead of an XML?
Have you tried to access the loaded XML inside of your service class? Does it work there?
2 Posted by roelof on 18 Sep, 2016 04:27 PM
[Inject] seems to have solved the problem, apologies for wasting your time; it was a silly mistake that I shouldn't have missed.
Support Staff 3 Posted by Ondina D.F. on 19 Sep, 2016 10:41 AM
Ah, don't worry :)
This kind of mistakes are easy to overlook, especially because there are no warnings, no errors thrown at compile- or runtime to give us a hint about what's wrong.
I wish you happy coding!
Ondina D.F. closed this discussion on 19 Sep, 2016 10:41 AM.