Write an expression binding for a control property. When does an expression become too complex, and what do you use instead?
Say your answer out loud first.
Practise another way
An expression binding puts a small calculation directly in the binding, for example visible="{= %{Status} === 'O' }" to show a button only for open orders.
The {= } form is one-way and recalculates; {:= } is one-time. I use it for comparisons and simple conditions.
Once it needs several branches, string building or reuse in more places, I move it to a formatter function in a formatter module. When the field must stay editable, I use a data type instead.
The syntax
SAP's documentation describes expression binding as an alternative to a custom formatter for trivial logic such as comparisons.
{= expression}: one-way, recalculated when model values change.{:= expression}: one-time, cheaper because no change listeners are kept.- Embed model values with
%{path}or${path}. SAP recommends%{...}by default: it is short fortargetType: 'any'. By contrast,${...}formats the value to the control property's type. This can fail with OData V4's automatic types (for example a string status bound to a booleanvisible).
<Button text="{i18n>approve}"
visible="{= %{Status} === 'O' && %{GrossAmount} > 1000 }"
press=".onApprove"/>
<ObjectStatus text="{Status}"
state="{= %{Status} === 'X' ? 'Error' : %{Status} === 'O' ? 'Warning' : 'Success' }"/>
<Text text="{:= ${i18n>createdBy} + ' ' + %{CreatedBy} }"/>
In XML, <, > and & must be escaped. An expression does not validate paths, so a typo gives no error (V4 logs a console warning).
When it is too much
Move to a formatter when:
- there are more than about two branches, or nested ternaries become unreadable;
- the logic needs helper calls (dates, number formatting, i18n texts with parameters);
- the same logic appears in several views;
- you want to unit test it (formatters are plain functions, easy to test with QUnit).
// model/formatter.js
sap.ui.define([], () => ({
statusState(sStatus) {
return { X: "Error", O: "Warning" }[sStatus] || "Success";
}
}));
<ObjectStatus state="{path: 'Status', formatter: '.formatter.statusState'}"/>
SAP's MVC guide puts formatters in the model folder, not in the controller.
The two-way catch
A formatter forces the binding to one-way. For an editable field that needs formatting and parsing (amounts, dates, units), use a data type such as sap.ui.model.odata.type.Decimal, which formats on display and parses user input.
The back-end alternative
Often the cleanest fix is upstream: a criticality field computed in the CDS view (@UI.lineItem: [{ criticality: 'StatusCriticality' }]) works in Fiori elements without any UI code.
Writes valid XML with escaping and %{} syntax, knows one-way versus one-time forms, and gives clear rules for moving to formatters or data types.
Writes JavaScript-like code that will not parse in XML, or puts every bit of display logic into long nested expressions.
Forgetting that XML needs < and && inside expressions, and using a formatter on an input field, which silently makes it read-only for the model.
- Why does SAP recommend %{} over ${} in expressions?
- How do you unit test a formatter?
- How would you show the status colour in a Fiori elements app instead?
2 candidate write-ups and 3 official pages. Confidence: high. Checked 1 Dec 2026.
- Official page Backs the answer.
- Official page Backs the answer.
- Official page Backs the answer.
- Candidate write-up Gives the question.
- Candidate write-up Gives the question.