
By using Event handling you can enable your mobile application to react to user actions or events raised by the service level of the system. When you perform the action during runtime, the event assigned to the action triggers the corresponding event handler.
The following types of event handlers are supported:
|
Entity |
Event Handler |
Description |
|
Data Object Node |
onCreated |
Called when a new instance of a Data Object (DO) node is created |
|
onLoaded |
Called when an instance of a DO node is loaded from the database |
|
|
Data Object Node Attribute |
onAttributeChanged |
Called when a DO node has an attribute value modified ** |
|
Data Structure |
onCreated |
Called when a data structure is instantiated |
|
Data Structure Attribute |
onAttributeChanged |
Called when an attribute within a data structure is modified ** |
|
Query |
onCreated |
Called when a query entity is instantiated |
|
onBeforeExecute |
Called before a query is executed |
|
|
onAfterExecute |
Called before after query is executed |
** N.b. attribute event handlers are defined on a specific attribute, not generically. However the generated method is generic and re-used by all attribute event handlers.
You have created an object on which you would like to define event handlers. The object can be one of the following types:
Data Object
Data Structure
Service with operations
Creation, deletion and displaying of event handlers is integrated into the Outline view of SAP NetWeaver Developer Studio (NWDS).
Select an entity in the Service Explorer tab that can have an associated event handler e.g. a Data Object
Using the outline view right click on the entity where you wish to add the event handler.
If this entity can have an event handler, the context menu will contain an item " Add Event Handler ".
In the "Add Event Handler" sub-menu click the type of event you wish to add.
Save the Data Object using File > Save
Double click the added event handler and the Java editor will open the relevant DO Java file at the newly added event handler function.
You may now proceed to add the Java code that you wish to execute for the entity event handler.
You have added an event handler to a service Data Object entity.
/**
* Created event handler will be called whenever a new instance
* of this class has created.
*/
protected void onCreated() {
//@@begin//OcaRoot/DataStructureHeader:com.sap.demo.serv_test.datastructure.Datastructure/structure/eventHandler:onCreated
//@@end
}