Lifecycle (Page and Flow) Events

Lifecycle events are defined by the system to indicate to a container (page, flow, or application) a change in its lifecycle. Event listeners are defined in a page or flow descriptor. When an event is raised, the framework calls the event listener with the name of the event defined in the descriptor.

Event listeners are defined in the page module under the “eventListeners“ property of the container model. Like all event types, a single event can have multiple event listeners. Event listeners call action chains and can pass parameters and return a payload.

The order of execution during navigation from page source to page target is:
  1. vbBeforeExit is dispatched to the source page.
  2. vbBeforeEnter is dispatched to the target page.
  3. vbExit is dispatched to the source page.
  4. vbEnter is dispatched to the target page.

Table 1-7 Lifecycle Events

Name Container Description Return
vbBeforeEnter Page

Dispatched to a page before navigating to it. At the point the event is dispatched, the previous page state still exists. Since the target page is not yet initialized, page variables are not available, but input parameters can be accessed using $parameters.

Navigation to the page can be canceled by returning an object with the property cancelled set to true. This is useful for redirecting to another page.

{cancelled: boolean}
vbEnter Page, Flow, Application

Dispatched after all page-scoped variables have been added and initialized to their default values, values from URL, or persisted values. This is a point where additional initialization work for the page (for example, data fetches) can be done. This event is "non-stopping" for a page, but can be stopped for other containers like application or flow. In other words, for application or flow, the processing of the web application will only continue after the chains called by the event ends.

None
vbBeforeExit Page

Dispatched to a page before exiting it. Navigation away from a page can be canceled by returning an object with the property cancelled set to true. This is useful when the page has dirty data and leaving the page should not be allowed before saving.

This event is dispatched to all pages in the current container hierarchy, starting with the leaf page (deepest nested page) and ending with the shell page (top level).

When navigation is triggered by browser history (forward or back button), the payload is an object with the following properties:
  • origin: (String) Specify what triggered the vbBeforeExit event. The only valid value is popState
  • direction: (String) Specify if vbBeforeExit was triggered by navigating backward or forward in the browser history
  • steps: (Number) Specify how many steps navigation goes backward or forward in the history stack
  • canBeCanceled: (Boolean) Whether navigation in the browser can be canceled by returning the object { cancelled: true } to the vbBeforeExit event.
{cancelled: boolean}
vbExit Page, Flow Dispatched when exiting the container (page or flow). This event can be used to clean up resources before leaving the page. None
vbBeforeAppInstallPrompt Page, Flow, Application Dispatched when a PWA receives a BeforeInstallPromptEvent from the browser. The event will be dispatched after vbBeforeEnter, but there is no guarantee that it will be dispatched after vbEnter. The vbBeforeAppInstallPrompt event can be used to display a native application install prompt by calling event.getInstallPromptEvent().prompt(). Currently, this is only supported in Chrome. For PWAs, the event will be handled automatically by the root page. { getInstallPromptEvent() }
vbAfterNavigate Page
Dispatched from the current page after navigation to this page is complete. The payload is an object with these properties:
  • currentPage: the path of the current page

  • previousPage: the path of the previous page

None
vbDataProviderNotification  
Dispatched when a Data Provider's implicit fetch fails with an error. The event has the following payload:
{
 severity: 'string', // severity level
 detail: 'any', // details of the error, this could have the Rest failure details
 capability: 'object', // object with the capabilities configured on the SDP
 fetchParameters: 'object', // object with the parameters passed to the fetch
 context: 'object', // object representing the state of the SDP at the time fetch was initiated
 id: 'string', // uniqueId of the SDP instance
 key: 'string', //  since the event can be fired multiple times, this identifies the event instance
},
None
vbResourceChanged  
Dispatched when an application has been updated. This event allows the application to notify the user that they need to refresh to view the updated application. A default handler resourceChangedHandler is added in the application template.
{
   error: {
      detail: 'string',
   },
}
None
vbNewContentAvailable

Dispatched when an updated Web PWA service worker has been activated. The event will be dispatched after vbEnter. A typical example of how an application can respond to a vbNewContentAvailable event is to open a dialog prompting the user to reload the page.

None