When we have extracted all data available to the event handler, how do we interact
with the user interface?
Note: Only synchronous event handlers can directly communicate with the UI, because
if the event has already happened (as it has, in the case of asynchronous handlers),
the user who triggered the event may already have been logged out.
-
You use three independent actions to interact with the TeamForge UI:
-
Add a success message to the UI that gets displayed as the result of
the action just triggered by the user.
This can be done by calling the addSuccessMessage
method of the EventHandler base class (see
SynchronousHookScriptEventListener.java of example two for
details).
-
Add an error message to the UI that gets displayed as the result of the
action just triggered by the user.
This can be done by calling the addErrorMessage
method of the EventHandler base class.
-
Block the event you intercepted.
This can be done by throwing an exception in the
processEvent method. The payload of your exception
will be displayed in the UI.
All three forms of UI feedback can be used in combination. For example,
it is possible to display an error message even if you did not block the event,
and it is possible to show many error and success messages
together.
-
What happens if the event in question was not triggered by a user logged into
the TeamForge Web UI but by a client
using the TeamForge web
services?
In this case, error and success messages do not reach the SOAP client.
However, the payload of the exception object thrown when the event was
blocked is delivered as part of the SOAP fault element.
-
While synchronous event handlers enable you to block events and/or to provide
additional feedback to the currently logged in user, they should not be used to
trigger follow-up actions (like changing TeamForge artifacts or interacting with
external systems).
Remember that these handlers are running in the main TeamForge event loop and nothing else
will happen until you return from the processEvent method,
so return as fast as you can.