org.zkoss.zk.ui.event
Class GenericEventListener<T extends Event>

java.lang.Object
  extended by 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
GenericEventListener()
           
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericEventListener

public GenericEventListener()
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 of Component.addEventListener(int, java.lang.String, org.zkoss.zk.ui.event.EventListener) or Page.addEventListener(java.lang.String, org.zkoss.zk.ui.event.EventListener).

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 interface EventListener<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 the bindComponent(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


Copyright © 2005-2011 Potix Corporation. All Rights Reserved. SourceForge.net Logo