Class GenericEventListener<T extends Event>
- java.lang.Object
-
- org.zkoss.zk.ui.event.GenericEventListener<T>
-
- All Implemented Interfaces:
java.io.Serializable
,EventListener<T>
,SerializableEventListener<T>
- Direct Known Subclasses:
GenericComposer
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>
- Since:
- 3.0.1
- Author:
- robbiecheng
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description GenericEventListener()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Method Detail
-
onEvent
public void onEvent(Event evt) throws java.lang.Exception
Description copied from interface:EventListener
Notifies this listener that an event occurs. To get the event, you have to register it first by use ofComponent.addEventListener(int, java.lang.String, org.zkoss.zk.ui.event.EventListener<? extends org.zkoss.zk.ui.event.Event>)
orPage.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)
.- Specified by:
onEvent
in interfaceEventListener<T extends Event>
- Throws:
java.lang.Exception
-
bindComponent
public void bindComponent(Component comp)
A convenient method that help you register this event listener to the specified target component.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.
- Parameters:
comp
- the target component to register this event listener.
-
unbindComponent
public void unbindComponent(Component comp)
A convenient method that help you remove this event listener from the specified target component. This is a counter method of thebindComponent(Component)
method.- Parameters:
comp
- the target component to remove this event listener.- Since:
- 3.6.3
-
getController
protected java.lang.Object getController()
Returns the controller that really implement the onXxx methods (default to this). It is intended to be overrode; you shall not have to call this method directly.- Since:
- 3.0.8
-
-