Asynchronous Tasks"
From Documentation
Line 1: | Line 1: | ||
{{ZKDevelopersReferencePageHeader}} | {{ZKDevelopersReferencePageHeader}} | ||
+ | |||
+ | If the task of updating UI can be represented as a method, the push can be done easily. All you need to do is | ||
+ | #Implement the UI updates in an event listener (implementing <javadoc type="interface">org.zkoss.zk.ui.event.EventListener</javadoc> or <javadoc type="interface">org.zkoss.zk.ui.event.SerializableEventListener</javadoc>). | ||
+ | #Then, schedule it for executed asynchronously by use of <javadoc method="schedule(org.zkoss.zk.ui.Desktop, org.zkoss.zk.ui.event.EventListener, org.zkoss.zk.ui.event.Event)">org.zkoss.zk.ui.Executions</javadoc>. | ||
+ | |||
+ | Here is the pseudo code: | ||
+ | <source lang="java"> | ||
+ | Executions.schedule(desktop, | ||
+ | new EventListener() { | ||
+ | public void onEvent(Event event) { | ||
+ | updateUI(); //whatever you like | ||
+ | } | ||
+ | }, event); | ||
+ | </source> | ||
+ | |||
+ | You could manipulate UI whatever you want in <javadoc type="interface" method="onEvent(org.zkoss.zk.ui.Event)">org.zkoss.zk.ui.event.EventListener</javadoc>. It is no different from any other event listener. | ||
+ | |||
+ | Notice that, since there is at most one thread to access the UI of a given desktop, the event listener's performance shall be good. If you have a long operation to do, you could implement it as [[ZK Developer's Reference/Server Push/Synchronous Tasks|a synchronous task]] or use [[ZK_Developer's_Reference/Event_Handling/Event_Queues#Asynchronous_Event_Listener|event queue's asynchronous event listener]]. | ||
=Version History= | =Version History= |
Revision as of 05:07, 23 November 2010
If the task of updating UI can be represented as a method, the push can be done easily. All you need to do is
- Implement the UI updates in an event listener (implementing EventListener or SerializableEventListener).
- Then, schedule it for executed asynchronously by use of Executions.schedule(Desktop, EventListener, Event).
Here is the pseudo code:
Executions.schedule(desktop,
new EventListener() {
public void onEvent(Event event) {
updateUI(); //whatever you like
}
}, event);
You could manipulate UI whatever you want in EventListener.onEvent(Event). It is no different from any other event listener.
Notice that, since there is at most one thread to access the UI of a given desktop, the event listener's performance shall be good. If you have a long operation to do, you could implement it as a synchronous task or use event queue's asynchronous event listener.
Version History
Version | Date | Content |
---|---|---|
5.0.6 | November 2010 | This feature was introduced. With 5.0.5 or prior, you have to use Event Queues or Synchronous Tasks. |