ZK Developer's Guide
ZK Developer's Guide
ZK Developer's Guide
- TAGS
- guide
- iknow.seforge.org
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Getting Started with <strong>ZK</strong><br />
}<br />
//It is possible to implement the method with an argument<br />
public void onOK(final KeyEvent event)<br />
{<br />
}<br />
The org.zkoss.zk.ui.Component interface offers two methods:<br />
addEventListener() and removeEventListener(). With these methods it's<br />
possible to add and remove event listeners dynamically. The event listener must be<br />
from type org.zkoss.zk.ui.event.EventListener.<br />
package sample;<br />
import org.zkoss.zk.ui.event.Event;<br />
import org.zkoss.zk.ui.event.EventListener;<br />
public class SampleEventListener implements EventListener<br />
{<br />
public boolean isAsap()<br />
{<br />
return true;<br />
}<br />
public void onEvent(final Event event)<br />
{<br />
//here we process the necessary instructions<br />
}<br />
}<br />
Now we can add this event listener in some initialization method.<br />
public void init(final Component component)<br />
{<br />
component.addEventListener("onClick", new SampleEventListener());<br />
}<br />
When should it be done?—ASAP<br />
The interface org.zkoss.zk.ui.event.EventListener has a<br />
method isAsap with the return value boolean.<br />
If the method returns true, the event will be sent to the server the<br />
moment the events occurs. However, if the method returns false, the<br />
event won't be sent to the server directly. It will be sent if another event<br />
occurs that has a positive isAsap. In case of performance problems there<br />
is a possibility to directly affect that point.<br />
Another way to handle events is to add an event listener to org.zkoss.zk.ui.Page.<br />
The consequence is that all events that belong to component from the page are send<br />
to that registered listener, too.<br />
[ 24 ]