The optimal aproach fo handling service events

misiuoperator's Avatar

misiuoperator

14 Aug, 2012 02:51 PM

Hi,
can someone tell me what is the best way to handle service response event?
I'm sending query to make remote service save my project, when it's done service shall respond 'ok' message to let my model update.
Here comes a problem for me (as you can see i'm robotlegs newbie) : how should i implement handling service response?

at SaveProjectCommand? - using commandMap.detain - registering Commands method as a handler (probably sth. like "onSaveProjectResult") - then manually update injected model ( projectModel.iSsaved = true ) - and finally do commandMap.release (this)

maybe at ProjectService? - injecting model into service and updating it from there like Service.saveProject >> Service.onSaveProjectResult >> projectModel.iSsaved = true

or do you go another way? what is your best practices for working with remote service and robotlegs?

  1. Support Staff 1 Posted by Ondina D.F. on 14 Aug, 2012 05:09 PM

    Ondina D.F.'s Avatar

    Hi misiuoperator,

    at SaveProjectCommand? –

    You can do that.

    maybe at ProjectService? –

    If you don’t need a reusable Service, you can inject the Model directly into it.

    If, on the other hand, you need to use the same Service elsewhere and you want to keep it loosely coupled and having just one responsibility, you shouldn’t inject the Model into it.

    In your Service.onSaveProjectResult() you can dispatch a custom event that triggers a Command that updates the Model. When its data changes, the Model dispatches an event, and interested Mediators would listen for it.

    I'm sending query to make remote service save my project, when it's done service shall respond 'ok' message to let my model update.

    Do you need to update only the projectModel.iSsaved in your Model, or is there more data that needs to be processed and sent to other parts of your application? Do you need to store iSsaved in your Model?

    If you just need to let one or more Mediators know that the data has been saved, and they don’t need anything else from the Model, you can let the Mediator(s) listen for an event dispatched in your Service.onSaveProjectResult.

    I hope that this is going to help you.
    Ondina

  2. Ondina D.F. closed this discussion on 25 Aug, 2012 02:40 PM.

  3. misiuoperator re-opened this discussion on 07 Sep, 2012 01:37 PM

  4. 2 Posted by misiuoperator on 07 Sep, 2012 01:37 PM

    misiuoperator's Avatar

    Thank you very much, i thought i send my thanks to you, but now i can see i didn't publish it somehow.

  5. Support Staff 3 Posted by Ondina D.F. on 07 Sep, 2012 02:20 PM

    Ondina D.F.'s Avatar

    You’re welcome!!

  6. Ondina D.F. closed this discussion on 07 Sep, 2012 02:20 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac