org.zkoss.zkdemo.test
Class NPEEventThreadInit

java.lang.Object
  extended by org.zkoss.zkdemo.test.NPEEventThreadInit
All Implemented Interfaces:
EventThreadInit

public class NPEEventThreadInit
extends java.lang.Object
implements EventThreadInit

A test of NPE in EventThreadInit.

Author:
tomyeh

Constructor Summary
NPEEventThreadInit()
           
 
Method Summary
 boolean init(Component comp, Event evt)
          Initialize the event processing thread before processing the event.
 void prepare(Component comp, Event evt)
          Prepares the initialization at the servlet thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NPEEventThreadInit

public NPEEventThreadInit()
Method Detail

prepare

public void prepare(Component comp,
                    Event evt)
             throws java.lang.Exception
Description copied from interface: EventThreadInit
Prepares the initialization at the servlet thread.

It is invoked in the servlet thread (and before EventThreadInit.init(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event)). Thus, you can NOT manipulate the deskop in this method.

If this method throws an exception, it will abort the execution and shows an error message to the end user. Note: EventThreadCleanup.cleanup(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event, java.util.List) won't be called if an exception is thrown in this method, since it executes in the main thread.

In addition to throwing an exception, you can prevent an event from processing by returning false in EventThreadInit.init(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event). The event is ignored 'silently' then.

Specified by:
prepare in interface EventThreadInit
Throws:
java.lang.Exception

init

public boolean init(Component comp,
                    Event evt)
             throws java.lang.Exception
Description copied from interface: EventThreadInit
Initialize the event processing thread before processing the event.

The simplest form is void init(Component c, Event e) {return true;}

Unlike EventThreadInit.prepare(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event), it is invoked in the event processing thread (and after EventThreadInit.prepare(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event)). Thus, you can manipulate the desktop in this method such as creating a component.

If you want to prevent an event from processing, you can return false in this method. For example, you might create a highlighted window and return false to prevent the user from accessing, if the system is too busy.

If the use of the event thread is disabled (Configuration.isEventThreadEnabled() returns false), this method is also invoked in the Servlet thread.

If this method throws an exception, it will abort the execution and shows an error message to the end user (unless it is cleaned up by EventThreadCleanup.cleanup(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.event.Event, java.util.List)).

Specified by:
init in interface EventThreadInit
Returns:
if it is initialized successfully. If false is returned, the event is ignored, i.e., no event handler/listener will be invoked.
Throws:
java.lang.Exception


Copyright © 2005-2009 Potix Corporation. All Rights Reserved.