Overview: Handling events
In this topic ...
Related Topics ...
We can use events to trap and process system events, user events, or events that you declare with an Event Declaration builder call. We can send data when firing an event as well as simply broadcasting that a particular action has occurred.
System Events
All models support the following pre-defined system events:
- System: OnWebAppLoad -- Fired each time a new instance of the model's WebApp is instantiated for a session.
- System: OnRequest -- Fired each time an external request is made (typically, from a browser) to the WebApp.
- System: OnUnhandledError -- Fired when an error occurs and is not handled by an explicit error handler.
- Page: pageName:OnPageLoad -- Fired each time the specified page is requested. Each page in the model gets its own OnPageLoad event declaration.
To process any of these events, you add an Event Handler builder call to the model and specify the action to perform when the event occurs.
User Events
As the user interacts with the HTML controls of your application, we can process those events with the HTML Event Action builder. This builder monitors a specified HTML control (added to the page by another builder) and performs an action when the specified event occurs. For example, if you wanted to submit a form when the user clicks on a link, you would use the HTML Event Action builder call.
Declared Events
We can declare application-specific events by adding an Event Declaration builder to a model. The Event Declaration builder adds a fireEventName method to the model that allows you to fire the event. Any models that have an identical Event Declaration builder call (either added directly or indirectly with an Imported Model) can handle that event.