SAPUI5 and SAP Fiori Tools
RAP / CDS / ODataintermediate

SAPUI5 and Fiori Tools Part 3: Data Binding — JSON Model, OData Model, Modes

Key takeaway

📌 KEY POINTS ✅ Binding connects controls to model data declaratively: {/path}, {model /path}, {relativePath}. ✅ JSONModel for UI state; OData V4 model for backend data; ResourceModel for texts (i18n). ✅ Binding modes: one-way, two-way (default for V4 inputs), one-time. 💡 Use formatters and expression binding for display logic — not controller code.

Explanation

📌 KEY POINTS
✅ Binding connects controls to model data declaratively: {/path}, {model>/path}, {relativePath}.

✅ JSONModel for UI state; OData V4 model for backend data; ResourceModel for texts (i18n).

✅ Binding modes: one-way, two-way (default for V4 inputs), one-time.

💡 Use formatters and expression binding for display logic — not controller code.

▶ SAPUI5 DATA BINDING TUTORIAL: JSONMODEL, ODATA MODEL AND BINDING MODES

━━━━━━━━━━━━━━━━━━━━
▶ 1. WHY BINDING MATTERS

Binding keeps UI controls connected to model data.

Instead of:

  • reading a value;
  • finding a control;
  • setting the value;
  • repeating this after every change;

you declare the relationship once.

━━━━━━━━━━━━━━━━━━━━
▶ 2. JSONMODEL

Use a JSON model for client-side state or small local datasets.

Example:

┏━━ CODE ━━━━━━━━━━━━
┃ const oModel = new JSONModel({

┃ customer: {

┃ name: "ABC Industries",

┃ status: "Active"

┃ }

┃ });

┃ this.getView().setModel(oModel);

┗━━━━━━━━━━━━━━━━━━━

View:

┏━━ CODE ━━━━━━━━━━━━
┃ <Text text="{/customer/name}" />

┗━━━━━━━━━━━━━━━━━━━

━━━━━━━━━━━━━━━━━━━━
▶ 3. NAMED MODELS

Use named models when different data concerns coexist.

Example:

  • default OData model;
  • "view" model for UI state;
  • "i18n" resource model.

┏━━ CODE ━━━━━━━━━━━━
┃ <ObjectStatus text="{view>/statusText}" />

┗━━━━━━━━━━━━━━━━━━━

━━━━━━━━━━━━━━━━━━━━
▶ 4. BINDING CONTEXT

A control can inherit a context.

In a list, each row has a context pointing to one entity.

Use the binding context instead of relying on row indexes.

━━━━━━━━━━━━━━━━━━━━
▶ 5. ODATA MODEL

For backend business data, use the appropriate OData model for the service version.

Do not load the entire service into a JSON model just to make it feel simpler.

OData models provide server-side behavior such as filtering, paging and write handling.

━━━━━━━━━━━━━━━━━━━━
▶ 6. ONE-WAY VERSUS TWO-WAY

One-way binding:
model → UI

Two-way binding:
model ↔ UI

Use two-way only where user edits should update model state.

For read-only dashboards, one-way can be simpler.

━━━━━━━━━━━━━━━━━━━━
▶ 7. FORMATTERS

A formatter is useful for presentation logic.

Example:

┏━━ CODE ━━━━━━━━━━━━
┃ statusText: function (sStatus) {

┃ return sStatus === "A" ? "Active" : "Inactive";

┃ }

┗━━━━━━━━━━━━━━━━━━━

Do not put database/business rules into formatters.

━━━━━━━━━━━━━━━━━━━━
▶ 8. FILTERING AND SORTING

Prefer binding-level filters and sorters.

For large remote datasets, push filtering to the service rather than downloading thousands of rows.

━━━━━━━━━━━━━━━━━━━━
▶ CHECKPOINT

You should understand:

  • model;
  • binding path;
  • named model;
  • context;
  • one-way/two-way;
  • formatter;
  • OData versus local JSON state.

━━━━━━━━━━━━━━━━━━━━
▶ INTERVIEW TAKEAWAY

“SAPUI5 data binding connects controls to model paths. I use JSONModel for local UI state and OData models for backend business data. I use binding contexts rather than row indexes, and I push filtering to the backend for large datasets.”

Code example

ABAP Code
// ===== Named models: default (OData), "view" (UI state), "i18n" (texts) =====onInit: function () {  const oViewModel = new sap.ui.model.json.JSONModel({ busy: false, editMode: false });  this.getView().setModel(oViewModel, "view");}, <!-- ===== Binding syntax in XML ===== --><!-- absolute path, default model --><Text text="{/PurchaseRequest(RequestUUID=4c2a…,IsActiveEntity=true)/Description}" /> <!-- relative path: resolved against the element/row binding context --><VBox binding="{/PurchaseRequest(RequestUUID=4c2a…,IsActiveEntity=true)}">  <Title text="{RequestID}" />  <Input value="{Description}" editable="{view>/editMode}" />   <!-- named model --></VBox> <!-- list binding: each row gets its own context --><List items="{ path: '/PurchaseRequest', parameters: { $select: 'RequestID,Status' } }">  <StandardListItem title="{RequestID}"                    info="{ path: 'Status', formatter: '.formatter.statusText' }" /></List> <!-- expression binding: small display logic inline --><ObjectStatus text="{Status}"              state="{= ${Status} === 'A' ? 'Success' : ${Status} === 'R' ? 'Error' : 'None' }" /> <!-- texts from i18n --><Button text="{i18n>save}" enabled="{= !${view>/busy} }" /> // ===== model/formatter.js =====sap.ui.define([], function () {  "use strict";  return {    statusText: function (sStatus) {      return { N: "New", S: "Submitted", A: "Approved", R: "Rejected" }[sStatus] || sStatus;    }  };}); // ===== Binding modes =====// OneWay  : model -> UI           TwoWay : model <-> UI (V4 inputs default)// OneTime : read once (static values, better performance for large lists)

Real project scenario

A table downloads 50,000 rows into a JSON model and filters them in the browser. Moving filtering/paging to the OData service dramatically reduces load time and memory.

Common mistakes

  • Huge remote datasets copied into JSONModel.
  • Index-based row logic.
  • Business rules inside formatter functions.
  • Wrong binding mode.

Best practices

  • Use named models for clear concerns.
  • Use contexts.
  • Push large-data operations to backend.
  • Keep formatter logic presentational.

Interview angle

Compare JSONModel and OData model. Explain binding context and why backend filtering matters.

Practice this lesson

Quick check

1. What is a JSONModel typically used for in a RAP-based freestyle app?

2. Which approach is risky for identifying the selected row in a table?

3. Which binding is resolved against the current row context in a list?

Interview questions

1. Explain SAPUI5 data binding: model types, binding types and binding modes.

Answer it in your own words first, then compare.

2. A table shows the same status text for every row although data differs. What is likely wrong?

Answer it in your own words first, then compare.

Practice more with Interview AI →

Reference-verified: the steps are checked against official SAP documentation and tutorials, and object and field names in the sample code are checked for consistency. The code has not been compiled or run on an SAP system by ERPClimb. Syntax marked release-dependent varies by SAP release, so check it in your own system.

More lessons in this topic

Interview questions on this topic

Related SAP topics