Class GenericEventListener<T extends Event>
- All Implemented Interfaces:
Serializable,EventListener<T>,SerializableEventListener<T>
- Direct Known Subclasses:
GenericComposer
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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbindComponent(Component comp) A convenient method that help you register this event listener to the specified target component.protected ObjectReturns the controller that really implement the onXxx methods (default to this).voidNotifies this listener that an event occurs.voidunbindComponent(Component comp) A convenient method that help you remove this event listener from the specified target component.
-
Constructor Details
-
GenericEventListener
public GenericEventListener()
-
-
Method Details
-
onEvent
Description copied from interface:EventListenerNotifies 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:
onEventin interfaceEventListener<T extends Event>- Throws:
Exception
-
bindComponent
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
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
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
-