public abstract class GenericEventListener<T extends Event> extends java.lang.Object implements SerializableEventListener<T>
An abstract event listener that you can extend and write intuitive onXxx event
handler methods; this class dispatch event to the implemented onXxx event handler methods
automatically. It also provides a convenient method bindComponent(org.zkoss.zk.ui.Component)
that you
can bind a target event component to this event listener easily.
Following is an example. Whenever onOK or onCancel is posted (or sent) to this event listener, it dispatch the control to the corresponding defined onOK() and onCancel() methods respectively. Note how the bindComponent() method bind this event listener to the main window.
<window id="main">
...
</window>
<zscript><!-- both OK in zscript or a compiled Java class -->
public class MyEventListener extends GenericEventListener {
public void onOK(Event evt) {
//doOK!
//...
}
public void onCancel() {
//doCancel
//...
}
}
new MyEventListener().bindComponent(main);
</zscript>
Constructor and Description |
---|
GenericEventListener() |
Modifier and Type | Method and Description |
---|---|
void |
bindComponent(Component comp)
A convenient method that help you register this event listener
to the specified target component.
|
protected java.lang.Object |
getController()
Returns the controller that really implement the
onXxx methods (default to this).
|
void |
onEvent(Event evt)
Notifies this listener that an event occurs.
|
void |
unbindComponent(Component comp)
A convenient method that help you remove this event listener from the
specified target component.
|
public void onEvent(Event evt) throws java.lang.Exception
EventListener
Component.addEventListener(int, java.lang.String, org.zkoss.zk.ui.event.EventListener<? extends org.zkoss.zk.ui.event.Event>)
or
Page.addEventListener(java.lang.String, org.zkoss.zk.ui.event.EventListener<? extends org.zkoss.zk.ui.event.Event>)
.
If you want to forward the event to other component,
use Events.sendEvent(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event)
.
onEvent
in interface EventListener<T extends Event>
java.lang.Exception
public void bindComponent(Component comp)
All public methods whose names start with "on" are considered as event handlers and the corresponding event is listened. For example, if the derived class has a method named onOK, then the onOK event is listened and the onOK method is called when the event is received.
comp
- the target component to register this event listener.public void unbindComponent(Component comp)
bindComponent(Component)
method.comp
- the target component to remove this event listener.protected java.lang.Object getController()
Copyright © 2005-2023 Potix Corporation. All Rights Reserved.