Event Driven Programming

From Documentation
Revision as of 04:03, 27 October 2010 by Sphota (talk | contribs)

Stop.png This article is out of date, please refer to http://books.zkoss.org/zkessentials-book/master/ for more up to date information.

Event Driven Programming

In the previous section, we saw how components are declared in ZUML (ZK User Interface Markup Language) to make up an application's user interface. Now we'll look into ZK's event driven programming model to make all the components in an application to work together to bring about functionality for our cause.

How Does Event Driven Programming Work in ZK

Event driven programming is widely adopted for responsive GUI experience. Each ZK component is acceptive of having event listeners registered to itself. A component registered with an event listener will listen to actions by a user or notifications forwarded by the ZK framework. Think of ZK components as a collection of nodes, while the events form the network channels needed to make the collection to work as a whole. Take the sample we saw in the previous section:
ZKEssentials Intro HelloGoodbye.png
we have 5 components in this demo, 1 Window, 2 Buttons, and 2 Label (one declared explicitly, while the "World !" is automatically assigned to another label component). The functionality is displaying in a label the string value which the user chooses, either "Hello", or "Goodbye".
Thus, breaking down this functionality we see the following events need to happen for this to work:

  • The buttons need to listen to user's click.
  • The first label needs to be informed of the update that will be applied to its value (from "" to "Hello" or "Good-bye").



At line

<window title="ZK Essentials" mode="overlapped" border="normal" width="250px">
	<label id="lbl"/>World !
	<button label="Hello " onClick="lbl.value = self.label"/>
	<button label="Good-bye " onClick="lbl.value = self.label"/>
</window>




Last Update : 2010/10/27

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