CallBack

(This tag must be placed inside an <EventHandlers> tag)

The CallBack tag allows you to call a method on the event target. The event target is the object that dispatched the event.

<CallBack method="methodToCall" arguments="{['argument1', 'argument2']}" />

The event target that will be called with this tag is always the object that dispatched the event, that is the object on which the method dispachEvent() was called. When the event that triggers the EventHandlers to execute is dispatched by a visual component that let the event bubble up, then the target will be this original dispatcher, the visual component. That is because we usually say "this.dispatchEvent(myEvent)", so "this" is the event dispatcher. However, when the event is dispatched using a different dispatcher ( ie: when you pass an IEventDispatcher to a non-visual component), then the target will be that dispatcher. That is because in those cases we usually say "myDispatcher.dispatchEvent(myEvent), so "myDispatcher" is the event target.

Attributes

method

String

required

The method to call on the event target. This method must be public.

<CallBack method="dataReceived" ... />

arguments

Array

not required

If the function in your event target has arguments, you can pass them via the "arguments" attribute. Suppose your "dataReceived" function has the following signature:

public function dataReceived(name:String, value:Number)

then you can pass those arguments as follows:

<CallBack
   method="dataReceived"
   arguments="{['Tom', 36]}"/>

Note that the arguments attribute expects an array. Besides passing literal values, you can pass values coming from the event that triggered the execution of the list of handlers, values coming from a service call, etc. The arguments attribute in the CallBack tag has the same functionality as the arguments in the MethodInvoker. See MethodInvoker for more examples.

targetId

String

not required

targetId can be used to only execute the method call if the event target's id matches the targetId specified. This can be used to distinguish between two different views dispatching the same event.

<CallBack
   method="dataReceived" targetId="dashboard" />
<CallBack
   method="dataLoaded" targetId="customers" />

In the above example, when certain event is dispatched, the method dataReceived will only be called on the target if the target's id is "dashboard", while the method dataLoaded will only be called if the target's id is "customers".

4 responses

  1. Is it possible to feed CallBack with a dynamic method name?
    Something like:
    <CallBack method="{event.resultCallback}" arguments="{[resultObject, event]}"/>
    (resultCallback being a string property of my custom event containing result handler method name)
    I would like to use EventMap only for mapping events to service calls and return result/fault in a simple manner to the caller.
    ResponseAnnouncer works just fine for that purpose but CallBack is a better solution because there are less events flying around and there is no mate specific code in the caller component.
    I tried using the syntax above but event.resultCallback is not parsed to method name.
  2. Is there anyway to add a timeout to a callback? Something like throwing a Fault it takes longer than a set value.
  3. It seems to break the Presentation model where a global dispatcher is used. The event target goes to main application instead of that Presentation model. any idea?
  4. Tim,<br />As explained in the above documentation, the dispatcher you use to dispatch the event is the target:<br />&quot;when the event is dispatched using a different dispatcher ( ie: when you pass an IEventDispatcher to a non-visual component), then the target will be that dispatcher.&quot;<br />Therefore, Callback will call whichever dispatcher you used (not the presentation model).

Comments now closed