pp108 : Types of Event Listeners

Types of Event Listeners

This topic describes the types of event listeners.

There are two types of event listeners:

  • Implicit Listeners
  • Explicit Listeners

Implicit Listeners


When you implement a Java method (logic) in an extension class of an object, it becomes an implicit listener. This implicit listener contains all the required information to act on a particular event.
For example, to perform some action such as checking constraints on an object before it is inserted into the database, use onBeforeInsert event listener. To invoke the listener implicitly, add a listener method such as onBeforeInsert to the extension class and add the code to implement the functionality.
Note: An implicit attribute-level event listener needs to follow the naming convention shown below:

on<listener name>_<attribute name>

For example, onInitialize_City, onAccess_Name. The name of the attribute is case-sensitive. Therefore, ensure that it is identical to the actual attribute defined in the object.

Explicit Listeners


When you create a class (outside the extension class) containing only the Java interface (no implementation), it becomes an explicit listener. Explicit listeners must be registered before they are invoked. For this purpose, WS-AppServer provides a class called Listeners , that contains several methods to register such explicit listeners.

Even here, to check constraint on an object before it is inserted into the database, use the onBeforeInsert event listener. However, to invoke the listener explicitly, you need to register a class that implements the IBeforeInsertListener interface.

Note: Use explicit listeners in situations where you want to use event listeners outside the scope of the extension class.

Difference between Implicit and Explicit Listeners

Implicit Listeners

Explicit Listeners

Is internal to an extension class

Requires registration with the Listeners class before being applied

Allows implementation of a single event listener

Allows implementation of multiple event listeners in a single class

Restricted to the logic within the class

Accommodates implementation of additional logic


Event Listener Precedence


If your application code contains implicit listeners and explicit listeners, then the implicit listeners are called first, followed by the explicit listeners.

For details on using the methods, see WS-AppServer SDK.

Tip: !!Click here to watch the video.

Related concepts

Event
Event Listener
Event Object
Event Trigger

Related reference

Event Listeners in WS-AppServer