1

I posted a question last night that after reading back sounded awful, so I deleted it and have come back to try again, this time properly.

I have a Flex Mobile App, that uses Parsley, everything works as expected but I am trying to do use a decoupled result handler in my controller, but it is not firing when I expect it to, so would like a pointer as to why.

The command look like this:

public function execute():void
    {
        var asyncToken:AsyncToken = Db.Instance.ViewChildren(mainModel.loggedInUser.userId);
        asyncToken.addResponder(new Responder(result, error));
    }

    public function result(result:ResultEvent):void
    {
        callback(result.result);
    }

    public function error(event:FaultEvent):void
    {
        callback(event.fault);
    }

Which works as expected, the command is executed and the result handler handles the result, the problem comes when I try to put a message handler in the controller for the view.

[CommandResult]
        public function handleResult(result:AsyncToken):void
        {
            trace("result in the controller");
        }
        [CommandError]
        public function handleError(fault:AsyncToken):void
        {
            trace('error: ' + fault.fault.faultDetail);
        }

Neither of these listeners fire when a result arrives, so I did the obvious thing and changed the code to:

[CommandResult]
        public function handleResult():void
        {
            trace("result in the controller");
        }
        [CommandError]
        public function handleError():void
        {
            trace('fault in controller);
        }

Now it fires, but I have no data handle.

I did think of changing the commands execute method to

public function execute():AsyncToken
{
return Db.Instance.ViewChildren(mainModel.loggedInUser.userId);
}

as after all it does return an AsyncToken, but then the command doesn't fire at all (it is part of a 2 command sequence that is mapped to an event called ChildEvent, this is the second and last event in the chain.

So in summary, I want the above to work, but want to be able to manage the result in the decoupled result handler, but I can't work out how, the parsley manual is great for getting to this point (http://www.spicefactory.org/parsley/docs/3.0/manual/?page=commands&section=intro), but the finer details are a little sketchy.

Thanks

Shaine Fisher
  • 315
  • 1
  • 3
  • 20
  • After lots of testing I have discovered that all I need to know is what should I put between the brackets in the decoupled result handler so I can see the result, after all of that long post it comes down to that. [CommandResult] public function handleResult(event:--what goes here--):void { trace("result in the controller"); } [CommandError] public function handleError(fault:--what goes here--):void { trace('fault in controller); } That makes it a little easier to manage as a question :) – Shaine Fisher Jun 03 '15 at 10:02
  • Something to note, when I run the app with the code as above, the command gets called and the result handler in the command gets fired, it traces 'result', but then so does the [ErrorHandler] in the controller, it traces 'fault in controller'. Could seriously do with some insight here because this is making no sense. Thanks – Shaine Fisher Jun 03 '15 at 10:28
  • Check if adding an `Event` type parameter, the one type which is the base of all Parsley framework events, will allow the callbacks to fire. If yes, use `event.info` or more precise parameter to query the result. Actually I haven't found the place in the manual you refer to where view controllers are described with such codes with square brackets, so maybe it'll be worthy to find the proper page. – Vesper Jun 03 '15 at 13:48
  • It's section '7.6 Handling Results and Observing Commands' in the Parsley 3.0 manual. I will test now and come back to you, thank you. – Shaine Fisher Jun 03 '15 at 13:52
  • @Vesper why would it not work in the Controller? I will test this in the View too just to eliminate this as a problem. I have the Model, View and Controller all linked in the Context, the Context is referenced in the View, and the Command(s) are mapped in the Context too, it works exactly as expected, but I want the controller to get the Result and manipulate the Model instead of the Command doing it because I need to be able to reuse the Command in a different section and alter a different Model from the same results. Does that make sense? – Shaine Fisher Jun 03 '15 at 13:58
  • Sadly, I can't make sense out of Parsley's MVC paradigm. Maybe someone more experienced in all this would come and shed light onto your troubles. – Vesper Jun 03 '15 at 14:14
  • I changed the Controller handlers to e:Event a e:Error respectively, when I run the command the result handler in the Command fires, but the Error handler in the controller, when I view the stack trace I this in the message field: "No converter registered for converting class org.spicefactory.lib.reflect.errors::ConversionError to class mx.rpc.events::FaultEvent" So, as I wasn't trying to use either of those types I am a little confused. Can someone translate what that means in real terms, and what my Handler types should be in the Controller handlers? – Shaine Fisher Jun 03 '15 at 19:23
  • Wow, a class conversion error! This means that a callback expected to accept `org.spicefactory.lib.reflect.errors::ConversionError` or its superclass, and your callback is declared to receive `mx.rpc.events::FaultEvent`. I'd wish there could be another such error with result handler (if it doesn't work already) so you could derive what class should a result handler accept. This error means your `handleError` should accept a parameter of `org.spicefactory.lib.reflect.errors::ConversionError` class or its superclass that is a more generic error class (aka a superclass to other error classes). – Vesper Jun 04 '15 at 06:46
  • Yeah I got that, but when I change handleError to accept ConversionError as a parameter it still gives me the same error, so I gave up on the error as I have a fault handler in the command. For the result however: The type of the result also has to match for this method to get invoked. Which means that the result type on my handleResult is wrong, which is why it isn't firing, but I cannot figure out what it wants, I have set it to event:ResultEvent, event:AsyncToken, but I don't actually know what it wants. Any ideas what it is asking for based on the initial command? – Shaine Fisher Jun 04 '15 at 07:39

1 Answers1

1

With a small tweak to the Controller code, we end up with this:

        [CommandResult(type="view.user.UserEvent", selector="loadUser")]
        public function handleResult(result:Object):void
        {
            trace("this is the command result");
        }

OR

        [CommandResult(selector="loadUser")]
        public function handleResult(result:Object, trigger:UserEvent):void
        {
            trace("this is the command result");
        }

Now this fires, I get an Object with my data in, resolved.

It would be useful to note that the manual for Parsley 3.0 misses out the section that explains how this actually works. I eventually found it in the Parsley 2.2 manual (the equivalent section in the 3.0 manual has been removed!) But if you ever need it http://www.spicefactory.org/parsley/docs/2.2/manual/messaging.php#command_methods

Thanks everyone!

Shaine Fisher
  • 315
  • 1
  • 3
  • 20