MAS 9.2 series framework 3.2.8xx a handful of names
The patterns come from the apps that IBM ships with a 9.2-series install. The demonstration runs in our Components Explorer, a small Maximo Mobile app we built for these articles, in the preview of our MAF editor. Details move with each release, and the shape holds.
One attribute, one method#
An event handler is an attribute whose value is the name of a method on a controller.
<button label="Save" on-click="saveRecord"/>class DetailPageController {
saveRecord() {
this.page.findDatasource("woDS").save();
}
}There is no registration step and no import. The framework takes the string, looks for a method of that name on the controllers in scope, and calls it. If no controller has the method, nothing happens and nothing complains, which is the failure mode to remember.
Scope matters here, because an unhandled event travels from the datasource to the page to the application.
A method defined on any of those three will catch it. A name defined in two of those places runs in both, which is a good reason to keep handler names distinctive.
We tried it with two buttons. The first names saveRecord, which our controller has: it runs and writes “saveRecord ran”. The second names saveRecrod, a typo. A tap on it changed nothing on the page, and the app wrote nothing to the browser console at its log level error.
<button id="fs_c_events_ok" kind="primary" icon="carbon:save"
label="Save (saveRecord)" on-click="saveRecord"/>
<button id="fs_c_events_typo" kind="secondary" icon="carbon:save"
label="Save (saveRecrod)" on-click="saveRecrod"/>The framework stays silent, so the check has to come from your tools. Our MAF editor reads the controllers of the app and marks the typo at the element, before the app ever runs:

Passing a value into the handler#
Most handlers need to know which record was tapped. That comes from a second attribute with the same name plus -arg.
<button label="Open" on-click="openRecord" on-click-arg="{item}"/>openRecord(item) {
this.app.setCurrentPage({ name: "details", params: { href: item.href } });
}The pairing is a rule the corpus keeps without exception. Many of the event attribute names end in -arg, and every one of them has a matching handler attribute of the same stem, with no orphans anywhere.
The eight names you will actually use#
The distribution is steep. A handful of handler names carry the large majority of all handlers written across the shipped apps.
| Attribute | Fires when |
|---|---|
on-click | the element is tapped |
on-change | an input’s value changes |
on-primary-action | the main button of a dialog or card is used |
on-item-click | a row or card in a list is tapped |
on-secondary-action | the second button of a dialog is used |
on-close-action | a dialog or panel is dismissed |
on-action | a generic action element is triggered |
on-blur | an input loses focus |
Listed from the most used to the least used, in the apps of the 9.2 series.
on-click alone is the most used handler by a wide margin, and it sits on more than one kind of element. Most of its uses are on buttons, followed by links and menu items, with a few on tabs, cards, images and switches.
The many other handler names split the rest between them, and some of them appear only once in the entire corpus. Those are specialised elements doing specialised things, such as on-scan for a barcode read or on-map-create for a map surface. Look them up when you meet the element, and do not try to learn them in advance.
Events you raise yourself#
The framework also has a programmatic bus. A controller emits a named event, and anything that subscribed to that name receives it.
// somewhere that knows something changed
this.app.emit("work-order-saved", { wonum });
// somewhere that cares
pageInitialized(page, app) {
this.app = app;
this.app.on("work-order-saved", this.refresh);
}It is useful when two parts of an app have no parent and child relationship and still need to stay in step. A detail page saves, a list somewhere else needs to know.
Use it sparingly, because the shipped apps do. Fewer than half of the apps call emit at all, and those that do use it sparingly, against a very large number of event attributes in markup. Events in this framework are overwhelmingly declarative, and the bus is the exception you reach for when the declarative path cannot connect two things.
When you do subscribe, remember that the subscription outlives the page unless you remove it. Take it down in pagePaused or keep a reference so you can.
Four things worth knowing early#
- A missing method is silent. The event fires, no controller answers, and the app carries on. When a button does nothing, check the spelling of the method name before anything else.
- The
-argattribute takes a binding.on-click-arg="{item}"passes the record itself, while the same value without braces passes the bare word. - The same name can be handled twice. Bubbling means a datasource controller and a page controller can both answer. That is occasionally what you want and usually a surprise.
- Not every element supports every handler. The attribute has to be one the element declares, so check the element in the reference before assuming
on-clickworks there.
What to read next#
- Controller Basics for the methods these attributes call.
- Understanding State Management for where a handler puts what it learns.
- Data Binding for how the
-argvalue reaches the handler.
