Send, Post and Echo Events from an Event Listener"
m (correct highlight (via JWB)) |
|||
(One intermediate revision by one other user not shown) | |||
Line 6: | Line 6: | ||
=== Post Events === | === Post Events === | ||
− | By use of the < | + | By use of the <code>postEvent</code> method in the <javadoc>org.zkoss.zk.ui.event.Events</javadoc> class, the application could post an event to the end of the event queue. This method returns immediately after placing the event into the queue. The event will be processed later after all events preceding it have been processed. |
=== Send Events === | === Send Events === | ||
− | By use of the < | + | By use of the <code>sendEvent</code> method in the <javadoc>org.zkoss.zk.ui.event.Events</javadoc> class, the application could ask ZK to process the specified event immediately. This method won't return until all event listeners of the specified event has been processed. The event is processed at the same thread. |
=== Echo Events === | === Echo Events === | ||
− | By use of the < | + | By use of the <code>echoEvent</code> method in the <javadoc>org.zkoss.zk.ui.event.Events</javadoc> class, the application could ask the client to echo back the event for processing later. This method returned immediately after queuing the response asking the client to echo back the event. |
− | Notice that, unlike < | + | Notice that, unlike <code>sendEvent</code> and <code>postEvent</code>, the event won't be processed in the current execution. Rather, it is processed later after the client echoes back the event. In other words, the event is processed later after the client has updated its user interfaces. Thus, it is useful to prompt the user before starting a long operation. |
− | For example, you can open a highlighted window and then invoke < | + | For example, you can open a highlighted window and then invoke <code>echoEvent</code> to do the long operation after the client shows the window (and echoes back the event). |
− | For example, we can use the [http://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/util/Clients.html#showBusy(java.lang.String) '''showbusy'''] method to show the busy message such that the user knows the system is busy. So, the end user will see "Execute..." first and then, after two seconds, "Done." in the following example. If you use < | + | For example, we can use the [http://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/util/Clients.html#showBusy(java.lang.String) '''showbusy'''] method to show the busy message such that the user knows the system is busy. So, the end user will see "Execute..." first and then, after two seconds, "Done." in the following example. If you use <code>postEvent</code>, the end user will see "Execute..." and "Done" at the same time after two seconds. |
<source lang="xml" > | <source lang="xml" > |
Latest revision as of 10:40, 19 January 2022
This documentation is for an older version of ZK. For the latest one, please click here.
In addition to receiving events, an application could communicate among event listeners by posting or sending events to them.
Post Events
By use of the postEvent
method in the Events class, the application could post an event to the end of the event queue. This method returns immediately after placing the event into the queue. The event will be processed later after all events preceding it have been processed.
Send Events
By use of the sendEvent
method in the Events class, the application could ask ZK to process the specified event immediately. This method won't return until all event listeners of the specified event has been processed. The event is processed at the same thread.
Echo Events
By use of the echoEvent
method in the Events class, the application could ask the client to echo back the event for processing later. This method returned immediately after queuing the response asking the client to echo back the event.
Notice that, unlike sendEvent
and postEvent
, the event won't be processed in the current execution. Rather, it is processed later after the client echoes back the event. In other words, the event is processed later after the client has updated its user interfaces. Thus, it is useful to prompt the user before starting a long operation.
For example, you can open a highlighted window and then invoke echoEvent
to do the long operation after the client shows the window (and echoes back the event).
For example, we can use the showbusy method to show the busy message such that the user knows the system is busy. So, the end user will see "Execute..." first and then, after two seconds, "Done." in the following example. If you use postEvent
, the end user will see "Execute..." and "Done" at the same time after two seconds.
<window id="w" title="Test echoEvent">
<attribute name="onLater">
Thread.sleep(2000);
Clients.showBusy(null, false);
new Label("Done.").setParent(w);
</attribute>
<button label="echo">
<attribute name="onClick">
Clients.showBusy("Execute...", true);
Events.echoEvent("onLater", w, null);
</attribute>
</button>
</window>