Event Firing

From Documentation

Overview

Events are usually fired (aka., triggered) by a component (when serving the user at the client). However, applications are allowed to send events too.

There are three ways to trigger an event: post, send and echo.

Post an Event

Posting is the most common way to trigger an event. By posting, the event is placed at the end of the event queue, while events stored in the event queue is processed one-by-one in first-in-first-out order. Each desktop has one event queue and all events are handled sequentially.

To trigger an event, you could invoke Events.postEvent(String, Component, Object). For example,

Events.postEvent("onClick", button, null); //simulate a click

In additions to post an event to the end of the event queue, you could specify a priority with Events.postEvent(int, String, Component, Object). By default, the priority is 0. The higher the priority the earlier an event is processed.

Notice that the invocation returns after placing the event to the event queue. In other words, the event won't be processed unless all other events posted earlier or with higher priority are processed.

Send an Event

If you prefer to trigger an event to a component directly and process it immediately without going thru the event queue, you could use Events.sendEvent(String, Component, Object) to trigger the event.

Events.sendEvent("onMyEvent", component, mydata);

Notice that the sendEvent method won't return until all handlers and listeners registered for this event has been processed. Also notice that the event handlers and listeners are invoked directly without starting any event thread (even if the event thread is enabled).

Echo an Event


Last Update : 2010/08/24

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.