↓ Skip to main content
A quilled board with four sockets down one side and nine lamps in a grid, six of them joined by coiled cords

Data Binding

A datasource holds the records and a page shows them, and the curly brace is what joins the two. It is the most-typed construct in MAML by a wide margin. It is also used for two jobs that look identical on the page and mean different things, and almost nobody says which is which.

MAS 9.2 series framework 3.2.8xx four roots, six shapes

This follows Datasource Basics, which ends where the data reaches the screen. Here is that join. The post covers what an expression may read from and the shapes it takes in practice. How the redraw actually happens underneath is the observer pattern, which has its own post later in this level.

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.

What a binding is
#

A binding is an expression in curly braces placed where an attribute value would go. The framework evaluates it, keeps watching what it read, and puts the result on the attribute. When the underlying value changes then the attribute changes with it, which is why a list redraws by itself when a load finishes.

<label id="lb_wonum" label="{item.wonum}" theme="16-bold"/>

That is the whole idea, and the rest of this post is the detail. Which names may appear on the left of the dot, and what you are allowed to write between the braces.

Binding is everywhere in the shipped apps. Almost every app uses it, and the few that carry none are a login shell and two library stubs.

The four roots
#

An expression reads from a named root, and there are four of them, plus a fifth form that names a datasource directly.

Across every braced attribute value in the apps of the 9.2 series.

RootWhat it is
page.this page’s own state, and its parameters
item.the current record, inside a list or a bound container
app.application state, plus the device and screen
dialog.the open dialog’s own state
a datasource idany datasource by name, for reading outside its own container

The first three roots appear in most apps. The dialog. root appears in only a few.

item is the one that confuses people, and the rule is short. Inside a list, a card group or any container bound to a datasource, item is the row being drawn. Outside such a container item means nothing, and you name the datasource instead: {fitWoDS.item.wonum} reads the current record of that datasource from anywhere on the page.

page and app differ only in who can see them. A value on page.state is visible to that page. A value on app.state is visible everywhere, which is how a detail page tells a list that something changed. Which one to pick is the subject of its own post later in this level.

app carries two things that are not state. app.device answers questions about where the app is running, and app.state.screen answers questions about size. {app.device.isMaximoMobile} is how a shipped app draws one layout on a phone and another in a browser, and it appears in most of the mobile apps.

The shapes
#

Six shapes cover essentially everything the shipped apps write between a pair of braces.

Read from the same MAML. An expression can fit more than one row, since a ternary may also contain a call.

ShapeExample
the whole value is one bindinglabel="{item.description}"
a binding mixed with literal textlabel="Task {item.taskid}"
a ternary choosing between two valuesheight="{app.device.screen.size === 'sm' ? 70 : 120}"
a leading negationhidden="{!page.state.canSave}"
a callon-click="{app.toast('Saved')}"
double braces for an argument objecton-click-arg="{{'item':item}}"

The first shape is by far the most common. The other five each appear regularly.

Four notes on those, in the order they bite.

A binding may hold an expression, and the corpus leans on that hard. Comparison, logical or, and a ternary all work, and nested ternaries appear where an app adapts a width to four screen sizes. Those are legal and they are hard to read, so keep an expression short enough that the next person can see its branches.

The double brace is a different thing from a nested single brace. {{...}} builds an object to hand to an event handler, which is why it clusters on on-click-arg and on-change-arg. Reading it as two nested bindings is the usual first mistake.

Mixing a binding with literal text works on some attributes only. The component reference marks those with a bindable-format flag, and only a limited set of attribute names carry it. The corpus binds far more attributes than that, mostly as a whole value, so read the flag as “a format string is supported here”, which is a narrower claim than the list of what can be bound.

A binding to something that is not there renders empty. No error, no console message, nothing in the build output. The usual cause is an attribute the schema never requested, which Datasource Basics covers: the server was never asked for it, so it arrives absent and the field draws blank. One detail differs when the binding sits inside literal text. In our explorer, a card label label="Missing attribute: [{item.status_description}]" over rows without that attribute drew Missing attribute: [{0}]. The {0} is the placeholder of the format string. A stray {0} on a screen points to the same cause.

Many bindings never show anything
#

Here is the finding that changes how the whole construct reads. Sort every bound attribute in the corpus by how often it carries a binding and the top of the list looks like this.

The most-bound attributes, in order, in the apps of the 9.2 series.

AttributeWhat it does
valueputs data in a field
labelputs data on a label
hiddendecides whether the element exists on screen
on-click-arghands an object to a handler
srcpoints an image at a source
disableddecides whether a control can be used

hidden sits third, above everything except the two attributes that put text on a screen. Group the list by job and the split is plain.

  • Attributes that display something, such as label, value, text, title and src, carry the most bindings.
  • Attributes that set state, such as hidden, disabled, readonly and required, carry fewer, and still a large part of all bindings.
  • Attributes that hand over arguments, such as on-click-arg, form a smaller group of their own.

So a large part of all binding decides whether a thing appears at all, and the larger part decides what it says. Many of the hidden bindings open with a negation, which is the shape hidden="{!page.state.somethingIsReady}".

d2 diagram d2 diagram

The same expression machinery, pointed at three different jobs.

Why this matters when you are reading somebody else’s app. A screen that looks wrong is as likely to be a state binding as a data one. The field is blank because hidden resolved true, or the button does nothing because disabled did. Neither leaves a trace in the log, and both are one expression away from the thing you were staring at.

And when you are writing one. The framework gives you conditional rendering for free, with no controller code. A great deal of what people write as JavaScript belongs in a hidden attribute, and the shipped apps show how far that goes.

One card, three jobs
#

The fragment below is ours, with ids that appear in none of the shipped apps.

<card-group id="fit_wo_cards" datasource="fitWoDS">
  <card id="fit_wo_card" slot="item">
    <label id="fit_wonum"
           label="Work order {item.wonum}"
           theme="16-bold"/>
    <label id="fit_status_label"
           label="{item.status_description}"
           theme="14-regular"/>
    <label id="fit_overdue"
           label="Overdue"
           theme="14-regular"
           hidden="{!item.isLate}"/>
    <button id="fit_open"
            label="Open"
            disabled="{page.state.busy}"
            on-click="openFitWorkOrder"
            on-click-arg="{{'item':item}}"/>
  </card>
</card-group>

Every root and every job is in that one card. The card-group binds the datasource, which is what makes item mean anything inside it. The first label mixes a binding with literal text, and the second is a whole-value binding. The third binds hidden from the record with a negation, so the word appears only on late work orders. The button binds disabled from page state and hands the whole row to its handler through a double brace.

The same card runs in our Components Explorer, with fitWoDS replaced by a JSON datasource of demo work orders. A button above the cards switches page.state.busy. On the left the page is idle. On the right it is busy, and every Open button is grey at once. The Overdue label stays on the late work order and stays off the other one, whatever the page state.

Two phone frames of Maximo Mobile, on the page “Bindings: one card, three jobs”. Each shows two work order cards. The first card, WO-1001, is late and shows Overdue. The second card, WO-1002, has no Overdue label. On the left “Page busy: no” and both Open buttons are blue. On the right “Page busy: yes” and both Open buttons are grey.
One card, three jobs: display, state and argument bindings, in Maximo Mobile on a phone, in the preview of our MAF editor

A tap on Open calls openFitWorkOrder with the object the double brace built. The handler reads arg.item.wonum, and the toast says “Open WO-1001”.

What to read next#

Binding is the join and the datasource is the supply, so read Datasource Basics if you have not. For the screens these expressions sit on, read Pages and Navigation. For the element vocabulary the braces live inside, read MAML Basics.


IBM’s own reference marks which attributes accept a format string, with the bindable-format flag on each attribute table. In the Application Configuration application, open the ? menu and choose Component Documentation.