Start an Action Chain From a Lifecycle Event
Lifecycle events are predefined events that occur during a page's lifecycle. You can start action chains when these events occur by creating event listeners for them. For example, if you want to initialize some component variables when the page opens, you can create an event listener in your artifact that listens for the vbEnter
event. You could then set the event listener to trigger an action chain that assigns values to the component's variables.
Before you create an event listener to trigger an action chain, it's important to understand a page's lifecycle, so you know where to plug in custom code to augment the page's lifecycle. Each page in your application has a defined lifecycle, which is simply a series of processing steps. These might involve initializing the page, initializing variables and types, rendering components, and so on.
Each stage of the lifecycle has events associated with it. You can "listen" for these events and start action chains whenever they occur to perform something based on your requirements. For example, to load data before a page loads, you can use the vbEnter
event and start an action chain that calls a GET REST endpoint.
Keep in mind that one or more pages make a flow and each flow has its own lifecycle.
This table describes the lifecycle events you can use to start action chains:
Lifecycle Event | Description |
---|---|
|
Triggered before navigating to a page. Commonly used when a user does not have permission to access a page and to redirect the user to another page (for example, a login screen). Because this event is dispatched to a page before navigating to it, you can cancel navigation by returning an object with the property For this event, you can use these variable scopes to get data:
|
|
Triggered after container-scoped variables have been added and initialized with their default values, values from URL parameters, or persisted values, and is dispatched to all flows and pages in the current container hierarchy and the application. Commonly used to fetch data. For this event, you can use these variable scopes to get data:
|
|
Triggered on all pages in the hierarchy before navigating away from a page. Commonly used to warn if a page has to be saved before the user leaves it, or to cancel navigation to a page (say, because a user doesn't have permissions to view that page) by returning an object with the property |
vbExit |
Triggered when navigating away from the page and is dispatched to all flows and pages in the current container hierarchy being exited from. Commonly used to perform cleanup before leaving a page, for example, to delete details of a user's session after logout. |
vbAfterNavigate |
Triggered after navigation to the page is complete and is dispatched to all pages and flows in the hierarchy and the application.
The event's payload (
$event ) is an object with the following properties:
|
vbNotification |
Triggered when a Fire Notification action is fired by the application. |
vbResourceChanged |
Triggered when an application has been updated. Commonly used to notify the user that they need to refresh to view the updated application. |
vbDataProviderNotification |
Triggered when a Data Provider's implicit fetch fails with an error. |
To start an action from a lifecycle event: