Class GenericEventListener<T extends Event>

  • 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
    • 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait