Send, Post and Echo Events from an Event Listener"

From Documentation
Line 18: Line 18:
 
For example, you can open a highlighted window and then invoke <tt>echoEvent</tt> to do the long operation after the client shows the window (and echoes back the event).
 
For example, you can open a highlighted window and then invoke <tt>echoEvent</tt> to do the long operation after the client shows the window (and echoes back the event).
  
For example, we can use the <javadoc>org.zkoss.zk.ui.util.Clients showbusy</javadoc> 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 <tt>postEvent</tt>, the end user will see "Execute..." and "Done" at the same time after two seconds.
+
For example, we can use the <javadoc>http://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/util/Clients.html#showBusy  showbusy</javadoc> 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 <tt>postEvent</tt>, the end user will see "Execute..." and "Done" at the same time after two seconds.
  
 
<source lang="xml" >
 
<source lang="xml" >

Revision as of 02:05, 27 July 2010

Send, Post and Echo Events from an Event Listener


Stop.png 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 Clients.html#showBusy 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>

A smalltalk



Last Update : 2010/07/27

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