Events and subscribers
Screen behavior is governed by events such as click event for a push button or blur event for any text widget.
- UI events
UI events are related to widget and their lifecycle. For example, the
onClick
event is raised on clicking a push button andafterSrceenInit
event is raised on initializing a screen. Generally, the format of all the UI event IDs are<uId of the widget>_<event name>
. For example, if theuId
of a widget isbCreate
and the event isonClick
, the UI event ID isbCreate_onClick
. - Business events
Business events are used in the application to control business logic on a screen. Generally, business events are not associated to any UI widget.
- Range 11 - 19 - Use any sequence number in the range of 11 to 19 when you want to add a subscriber before an application-provided subscriber
- Range 51 - 99: Use any sequence number in the range of 51 to 99 when you want to add a subscriber after an application-provided subscriber.
All the other sequence numbers are reserved. Therefore, ensure not to use them.
- It is suggested that you do not define subscribers with the same sequence number. Otherwise, the subscribers might be randomly called.
- The order and type of arguments that are received in local and global subscribers for an event differs.
- The sequence in which the local or global subscribers are called might differ, if a subscriber is used to do any asynchronous task such as opening a new screen or wizard in an editor.
- When you are defining subscribers for an event by using the IBM® Extensibility Workbench, you need not provide the sequence numbers as they are automatically generated based on whether you choose to add subscriber before or after an existing one.
The following scenarios describe the process of adding local subscribers to an event:
Add subscribers to an event after the application-provided subscriber
You can add a subscriber for thebCreate_onClick
UI
event after the application-provided subscriber with a sequence number
in the range of 51 - 99. For example, if the application-provided
subscriber definition is as follows: subscribers: {
local: [{
eventId: 'bCreate_onClick',
sequence: '25',
handler: {
methodName: "createOrderAction"
}
}]
}
You can add a subscriber in the screen extension as follows:subscribers: {
local: [{
eventId: 'bCreate_onClick',
sequence: '51',
handler: {
methodName: "extn_createOrderAction_after"
}
}]
}
Add subscribers to an event before the application-provided subscriber
You can add a subscriber for thebCreate_onClick
UI
event before the application-provided subscriber with a sequence number
in the range of 11 - 19. For example, you can add a subscriber in
the screen extension as follows:subscribers: {
local: [{
eventId: 'bCreate_onClick',
sequence: '19',
handler: {
methodName: "extn_createOrderAction_before"
}
}]
}
Stop the execution of an application-provided subscriber for an event
To stop the execution of an application-provided subscriber, use thesc.plat.dojo.utils.EventUtils.stopEvent
utility
and add a subscriber before the application-provided subscriber.- The
sc.plat.dojo.utils.EventUtils.stopEvent
utility is applicable only for local subscribers. - If you do any asynchronous task such as opening a new screen or
a wizard, use the
sc.plat.dojo.utils.EventUtils.stopEvent
utility before you do the task.
Add subscribers to an event that does not have an application-provided subscriber
To add a subscriber to an event that does not have an application-provided subscriber, use the subscriber sequence in the allowed range.- When you add a subscriber to an event in which the
handler
does some asynchronous operation such as Ajax request, the subsequent subscriber might not be called in the defined sequence. - The procedure to add subscribers to a UI or business event is the same. Only the event ID is different for each event.
- By default, the subscriber definition is present in the
local
property. When you add a global subscriber to an event, the subscriber properties can be added under theglobal
property ofsubscribers
. - If you create a new screen, add the subscriber property in the
<Screen>UI.js
file. If you extend an existing screen, define or generate the subscriber property in the<ScreenExtension>UI.js
file. - The
handler
can be a method that is defined in the screen extension or a utility method. If thehandler
is a utility method, the subscriber definition is as follows:subscribers: { local: [{ eventId: 'beforeEditorClosed', sequence: '25', handler: { methodName: "handleEditorClose", className: "UIUtils", packageName: "
ias.utils
" } }], }Here,
handler
refers to
, a methodias.utils
.UIUtils.handleEditorClosehandleEditorClose
defined in the
utility.ias.utils
.UIUtils
For more information about event-related utility methods, see the JavaScript documentation.