Event Listening

From Documentation

There are two ways to listen an event: an event handler and an event listener.

Listen by use of an Event Handler

An event handler is a method specified as an event attribute of a ZK page or as a member of a component class.

For example, we can declare an event handler by specifying an event attribute[1] as follows.

<button label="hi" onClick='alert("Hello")'/>

where the content of the event handler is the code snippet in Java. The event handler will be interpreted at the run time (by use of BeanShell). If you prefer to use other language, you could specify the language name in front of it. For example, the following uses Groovy as the interpreter:

<button label="hi" onClick="groovy:alert('Hi, Groovy')"/>

The other way to have an event listener is to declare it as a member of a component class. For example,

public class MyButton extends Button {
    public void onClick() {
        Messagebox.show("Hello");
    }
}

However, this approach is recommended if


  1. An event attribute is an attribute starting with on
Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.