SAPUI5 and OpenUI5 Basics
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
Almost every screen that an SAP user sees in a web browser, from the SAP Fiori launchpad to the list of purchase orders, is drawn by a JavaScript library called UI5. A newcomer meets UI5 as soon as they have to change one of those screens or build a small app next to SAP S/4HANA. UI5 comes in two editions: SAPUI5, which SAP ships with its products and publishes on ui5.sap.com, and OpenUI5, the open source edition that anyone can download from npm under the Apache License 2.0. This page takes you from nothing to a working two-screen app that lists expense claims from an OData service and opens one claim on a second screen. It explains the five ideas that every UI5 app uses (views written in XML, controllers written in JavaScript, models that hold data, data binding that connects the two, and routing that moves between screens), and the command line tools that serve and build the app. The page is written against SAPUI5 1.154 (the release labeled 2611, a maintenance release) and OpenUI5 1.154.0; SAPUI5 1.148 is the release marked for long-term maintenance. UI5 runs in the browser, so what you learn here applies whether the app is later deployed to an SAP S/4HANA system, to SAP BTP or to a plain web server. Every listing on this page was run for real on 2026-11-13, with OpenUI5 1.154.0 and a small CAP service as the data source, and the output shown is the output it produced. The parts that need an SAP system or an SAP BTP account are labeled as not run here.
Before you read
-
JavaScript Modules: UI5 loads code in modules, and the module idea is the same, although UI5 has its own loader.
-
Browser DOM Basics: what a web page and its elements are, because UI5 builds a page for you.
-
CAP Getting Started: the service that supplies the data on this page is a tiny CAP project; the page shows it in full, but you meet its tools there.
-
SAP Fiori Launchpad: the page that starts most UI5 apps in an SAP system.
-
Installing Node.js: the UI5 command line tools run on Node.js.
Key terms
-
SAPUI5: the edition of UI5 that SAP ships with its products, with more libraries than OpenUI5.
-
OpenUI5: the open source edition of UI5, licensed under the Apache License 2.0.
-
MVC (Model View Controller): the split of an app into data (model), screen (view) and the code that connects them (controller).
-
XML view: a screen described as an XML file that names UI controls.
-
Controller: the JavaScript file that reacts to what the user does on one view.
-
Data binding: the link that keeps a screen element and a value in a model equal, in one or both directions.
-
manifest.json: the descriptor file that declares an app’s models, routes and library dependencies.
-
OData: the web protocol in which the claims reach the app.
-
UI5 Tooling (UI5 CLI): the
ui5command that serves and builds an app.
What UI5 is and which edition to use
UI5 is a client-side library: the browser downloads JavaScript, and the library creates the page elements on the
screen. Its parts are libraries named like packages. sap.ui.core holds the base (modules, models, routing),
sap.m holds the mobile-friendly controls (a control is a screen element such as a button, a table or a text), and
sap.ui.layout holds layout helpers such as forms. An app lists the libraries it needs, and the loader fetches only
those.
The two editions share the same base. The README of the OpenUI5 repository describes it as a library that lets you build
web applications that respond to all devices, with data binding to JSON, XML and OData models, licensed under the Apache
License 2.0. SAPUI5 is the edition that SAP delivers with its products. Checked on npm on 2026-11-13, the OpenUI5
libraries are published as @openui5/sap.m (and the other libraries) with the license Apache-2.0, while the
Fiori elements library sap.fe.templates is published as @sapui5/sap.fe.templates 1.154.0 and the name
@openui5/sap.fe.templates returns "not found". That is the practical difference for this section: the freestyle
screens on this page use only libraries that exist in both editions, and the ready-made Fiori elements floorplans belong
to SAPUI5.
The version overview that SAP publishes as a machine-readable file lists, on 2026-11-13, the active version 1.154.0 (label 1.154 (2611), support "Maintenance"), and 1.148 (2605) flagged as a long-term-support release. UI5 follows a compatibility rule that SAP states explicitly: a minor release can add APIs but must not contain incompatible changes to the public API, which is defined by the API Reference, so code that uses only documented functions keeps working across 1.x updates. HTML and CSS that UI5 generates are not part of the public API.
The app at a glance
The running example is the expense claim from the rest of this section. A claim has an identifier, an employee, a status
and an amount. On this page the claims come from a tiny CAP service (shown below) that holds four claims, and the app
has two screens: a list of claims and a detail screen for one claim. The lab uses a reduced version of the claim table
(claim_id, employee_id, status, amount); the full model of the running example appears in the ABAP pages.
Source: drawn from the behavior of the app built on this page and the MVC description at Model View Controller (MVC)
The project has this layout. The folder webapp is the app; everything else is tool configuration.
ui/
package.json
ui5.yaml
webapp/
index.html
Component.js
manifest.json
i18n/i18n.properties
i18n/i18n_en.properties
view/App.view.xml
view/ClaimList.view.xml
view/ClaimDetail.view.xml
controller/App.controller.js
controller/ClaimList.controller.js
controller/ClaimDetail.controller.js
Source: the lab project of this page (copied from the scratch folder where it was run), layout as in the walkthrough at UI5 Walkthrough
Bootstrapping: index.html
Bootstrapping is the name for loading and starting UI5 from a web page. The page only has to load one script,
resources/sap-ui-core.js, and tell it where to find your code and which component to start.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Expense Claims</title>
<script id="sap-ui-bootstrap"
src="resources/sap-ui-core.js"
data-sap-ui-theme="sap_horizon"
data-sap-ui-compat-version="edge"
data-sap-ui-resource-roots='{ "demo.claims": "./" }'
data-sap-ui-on-init="module:sap/ui/core/ComponentSupport"
data-sap-ui-async="true"></script>
</head>
<body class="sapUiBody">
<div data-sap-ui-component data-name="demo.claims" data-id="container" data-settings='{ "id": "demo.claims" }'></div>
</body>
</html>
Source: index.html of the lab project; the bootstrap options follow Bootstrapping: Loading and Initializing
The attribute data-sap-ui-theme picks the look (sap_horizon is the Horizon theme). data-sap-ui-resource-roots
maps the namespace demo.claims to the folder of the page, so that demo.claims.view.ClaimList is found in
view/ClaimList.view.xml. The div with data-sap-ui-component tells the module ComponentSupport which component to
start, and data-sap-ui-on-init runs it once UI5 is ready. The setting data-sap-ui-compat-version="edge" is the one that
matters most to a beginner: the Bootstrapping page shows it in its snippet, and in this lab, without it, the longer
binding expressions written in the views below were read as a plain path and the table stayed empty ("No data"). With it,
UI5 reads the full binding syntax. The older spelling data-sap-ui-oninit still ran in the lab, but UI5 logs that
sap-ui-oninit is deprecated and asks for sap-ui-on-init, so the page uses the new name.
The Compatibility Rules page and the Configuration Options and URL Parameters page list the other options. One of those
parameters is useful at once: opening the page with ?sap-ui-language=en forces the English texts and number formats,
which is how the outputs on this page were read, because the browser used for the runs was set to Spanish.
Modules with sap.ui.define
UI5 code lives in modules, and every controller, component and helper file starts with the same call, sap.ui.define.
Its first argument is the list of modules that the file needs, and its second is a function that receives them, in the
same order, and returns what the file offers. The loader fetches the listed modules before it runs the function, so you
never load a script by hand.
sap.ui.define([
"sap/ui/core/UIComponent"
], (UIComponent) => {
"use strict";
return UIComponent.extend("demo.claims.Component", {
metadata: {
manifest: "json",
interfaces: ["sap.ui.core.IAsyncContentCreation"]
},
init() {
UIComponent.prototype.init.apply(this, arguments);
this.getRouter().initialize();
}
});
});
Source: Component.js of the lab project (run), following Components and the walkthrough at UI5 Walkthrough
The names in the list are paths: sap/ui/core/UIComponent is the class sap.ui.core.UIComponent. The component is the
unit that owns an app: it reads manifest.json (manifest: "json"), creates the models and the router that the manifest
declares, and shows the root view. The call this.getRouter().initialize() starts the router, which reads the URL and
shows the matching screen. The extend call creates a class whose name is the first argument; it is the same name as
the file path with dots, which is how UI5 finds it.
The manifest: manifest.json
manifest.json is the descriptor of the app. It declares the id and the title, the data source, the libraries,
the models, the root view and the routing, so that Component.js can stay short. This is the whole file of the lab app.
{
"_version": "1.65.0",
"sap.app": {
"id": "demo.claims",
"type": "application",
"title": "{{appTitle}}",
"applicationVersion": { "version": "1.0.0" },
"dataSources": {
"claimService": {
"uri": "/odata/v4/claim/",
"type": "OData",
"settings": { "odataVersion": "4.0" }
}
}
},
"sap.ui5": {
"rootView": {
"viewName": "demo.claims.view.App",
"type": "XML",
"id": "app"
},
"dependencies": {
"minUI5Version": "1.154.0",
"libs": { "sap.m": {}, "sap.ui.core": {}, "sap.ui.layout": {} }
},
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": { "bundleName": "demo.claims.i18n.i18n", "supportedLocales": ["en"], "fallbackLocale": "en" }
},
"": {
"dataSource": "claimService",
"settings": { "operationMode": "Server", "autoExpandSelect": true }
}
},
"routing": {
"config": {
"routerClass": "sap.m.routing.Router",
"type": "View",
"viewType": "XML",
"path": "demo.claims.view",
"controlId": "app",
"controlAggregation": "pages",
"async": true
},
"routes": [
{ "name": "list", "pattern": "", "target": "list" },
{ "name": "detail", "pattern": "claims/{claimId}", "target": "detail" }
],
"targets": {
"list": { "id": "list", "name": "ClaimList" },
"detail": { "id": "detail", "name": "ClaimDetail" }
}
}
}
}
Source: manifest.json of the lab project (run); structure described at Manifest (Descriptor for Applications, Components, and Libraries) and Model Instantiation and Data Access
Three parts deserve a closer look. The dataSources entry gives the service URL and states that it is OData 4.0; the
models entry with the empty name "" points at it, which makes it the default model, the one that a binding without a
model name uses. The i18n entry creates a resource model for the texts of the app (see below). The routing part is
described in its own section. Two settings of the default model were found by running the app, not by reading: with
autoExpandSelect set to true the model builds the $select list from what the views actually bind (see the
requests below), and a list binding with a sorter stopped with the message Error: Unsupported operation mode: undefined in the browser log when operationMode was left out, so the lab sets it to "Server", which means that
sorting and filtering are done by the service.
Views in XML
A view describes a screen. This page uses the XML view, the format of the walkthrough, because the structure of the screen is easy to read; the
Views page of the SDK describes the view types. Each tag
is a control, written with the library it comes from as a namespace: xmlns="sap.m" makes <Page> mean
sap.m.Page, and a prefix such as xmlns:mvc="sap.ui.core.mvc" gives the root tag mvc:View.
The shell of the app is the smallest view of all: a single App control that will contain the screens.
<mvc:View
controllerName="demo.claims.controller.App"
displayBlock="true"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc">
<App id="app" />
</mvc:View>
Source: App.view.xml of the lab project (run), see Views
Its controllerName is the controller file, and the id of the App control is the controlId that the router
uses, in the routing part above, to place a screen. The second view shows the list of claims.
<mvc:View
controllerName="demo.claims.controller.ClaimList"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc">
<Page id="listPage" title="{i18n>listTitle}">
<Text id="greeting" class="sapUiSmallMargin" text="{view>/greeting}" />
<Table
id="claimTable"
updateFinished=".onUpdateFinished"
items="{
path: '/Claims',
sorter: { path: 'claim_id' }
}">
<columns>
<Column><Text text="{i18n>colClaim}" /></Column>
<Column><Text text="{i18n>colEmployee}" /></Column>
<Column><Text text="{i18n>colStatus}" /></Column>
<Column hAlign="End"><Text text="{i18n>colAmount}" /></Column>
</columns>
<items>
<ColumnListItem type="Navigation" press=".onItemPress">
<cells>
<ObjectIdentifier
title="{
path: 'claim_id',
type: 'sap.ui.model.odata.type.Int32',
formatOptions: { groupingEnabled: false }
}" />
<Text text="{employee_id}" />
<ObjectStatus
text="{
path: 'status',
formatter: '.formatStatus'
}" />
<ObjectNumber
number="{
path: 'amount',
type: 'sap.ui.model.odata.type.Decimal',
constraints: { precision: 9, scale: 2 }
}"
unit="EUR" />
</cells>
</ColumnListItem>
</items>
</Table>
</Page>
</mvc:View>
Source: ClaimList.view.xml of the lab project (run), controls from sap.m, binding syntax per Binding Syntax
Every curly-brace text in this file is a data binding, explained in the next sections. Attributes that start with a
dot, such as press=".onItemPress", name a function of the view’s controller. The type="Navigation" on the list item
makes the whole row clickable and shows the arrow. Controls get an id where code or a test needs to find them, such
as claimTable; UI5 prefixes the id with the id of the view, so the same id can be used in several views.
The detail screen shows one claim in a form from sap.ui.layout, which is why the manifest lists that library.
<mvc:View
controllerName="demo.claims.controller.ClaimDetail"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc"
xmlns:f="sap.ui.layout.form">
<Page
id="detailPage"
title="{i18n>detailTitle}"
showNavButton="true"
navButtonPress=".onNavBack">
<f:SimpleForm editable="false" layout="ResponsiveGridLayout">
<Label text="{i18n>colClaim}" />
<Text
id="detailId"
text="{
path: 'claim_id',
type: 'sap.ui.model.odata.type.Int32',
formatOptions: { groupingEnabled: false }
}" />
<Label text="{i18n>colEmployee}" />
<Text id="detailEmployee" text="{employee_id}" />
<Label text="{i18n>colAmount}" />
<Text
id="detailAmount"
text="{
path: 'amount',
type: 'sap.ui.model.odata.type.Decimal',
constraints: { precision: 9, scale: 2 }
}" />
</f:SimpleForm>
</Page>
</mvc:View>
Source: ClaimDetail.view.xml of the lab project (run), see Views
Each value in the form has a Label before it, so that a person using a screen reader hears what a value means, not
only the value. Accessibility is a property of the whole page, not only of the library, so the general rules for
accessible web pages (text alternatives, keyboard use, contrast) apply to a UI5 app as well; they are on the page
Web Accessibility.
Controllers
A controller is a JavaScript module that holds the functions a view calls. It is created with the same sap.ui.define
and extends the base class sap/ui/core/mvc/Controller. UI5 calls onInit once, when the view is created, which is the
place to create models that only this view needs.
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel"
], (Controller, JSONModel) => {
"use strict";
const STATUS_TEXT = { N: "New", A: "Approved", R: "Rejected" };
return Controller.extend("demo.claims.controller.ClaimList", {
onInit() {
// A JSON model for state that belongs to this view only.
this.getView().setModel(new JSONModel({ greeting: "" }), "view");
},
onUpdateFinished(event) {
const count = event.getParameter("total");
const text = this.getView().getModel("i18n").getResourceBundle()
.getText("greeting", ["Alice", count]);
this.getView().getModel("view").setProperty("/greeting", text);
},
formatStatus(status) {
return STATUS_TEXT[status] || status;
},
onItemPress(event) {
const claimId = event.getSource().getBindingContext().getProperty("claim_id");
this.getOwnerComponent().getRouter().navTo("detail", { claimId });
}
});
});
Source: ClaimList.controller.js of the lab project (run), see Controller
Each function has a clear job. onUpdateFinished is the handler of the table’s updateFinished event, which fires after
the table has received rows; it asks the resource bundle for the text greeting, filling the placeholders {0} and
{1} with a name and the number of claims, and writes the result into the view’s own JSON model, from which the Text
control shows it. formatStatus is a formatter: it turns the one-letter code of the service into a word for the
screen. onItemPress reads the claim id from the row that was clicked and asks the router to go to the route detail.
A first attempt of this controller registered the same code in onInit by asking the table for its binding there; the
browser log showed Cannot read properties of undefined (reading 'attachEventOnce'), because the table has no binding
yet while the view is being created, so work that needs data waits for an event such as updateFinished. The other two
controllers are short.
sap.ui.define([
"sap/ui/core/mvc/Controller"
], (Controller) => {
"use strict";
return Controller.extend("demo.claims.controller.ClaimDetail", {
onInit() {
this.getOwnerComponent().getRouter()
.getRoute("detail").attachPatternMatched(this.onRouteMatched, this);
},
onRouteMatched(event) {
const claimId = event.getParameter("arguments").claimId;
this.getView().bindElement({ path: `/Claims(${claimId})` });
},
onNavBack() {
this.getOwnerComponent().getRouter().navTo("list");
}
});
});
Source: ClaimDetail.controller.js of the lab project (run); App.controller.js is the empty Controller.extend("demo.claims.controller.App", {}), see Routing and Navigation
Models and data binding
A model holds data outside the screen, and data binding connects a control property to a value in a model. UI5 has several model types with the same binding syntax; this page uses three.
-
The resource model holds the texts of the app (
i18n). It is read-only. -
The JSON model holds data in a JavaScript object that your code creates and changes. It is the right choice for small state that belongs to the app, such as the greeting above, or for mock data.
-
The OData V4 model reads and writes data of an OData V4 service and is the one the claims come from.
A binding is written in curly braces. The text before the > is the name of the model and the text after it is a path
into the model. {i18n>listTitle} reads the key listTitle of the model named i18n, {view>/greeting} reads the
property greeting of the JSON model named view, and {employee_id} has no model name, so it reads from the default
model, the OData model, at the context of the row it sits in. A binding of a whole list, such as
items="{ path: '/Claims', sorter: { path: 'claim_id' } }", is an aggregation binding: UI5 creates one list item for each
entry of the collection and uses the <items> content as the template for each. The inner bindings are relative, so
{employee_id} means the employee_id of the claim that the row stands for. Binding to a property updates the control
when the model changes, and the JSON and OData models also support writing back, called two-way binding, when a control
changes the value.
A binding may carry more than a path. type names a data type that formats the value for display and checks what a user
types, and formatter names a function of the controller. The amount in the table uses the OData type
sap.ui.model.odata.type.Decimal with the constraints the service declares (precision: 9, scale: 2), which is why
120.50 is shown with two decimals in the output below and is formatted by the language of the user. The claim id uses
Int32 with groupingEnabled: false; without it, a number such as 1001 is shown as 1,001 in English because the
integer type groups thousands by default. The Formatting, Parsing, and Validating Data page of the SDK explains the
data types.
The OData V4 model and the service behind it
The default model in manifest.json is an OData V4 model. Its constructor needs a service URL, and the Model
Instantiation and Data Access page states that one model instance covers one service. The service of the lab is a
two-file CAP project, run with CAP Node.js 10.2 (@sap/cds 10.2.2) on Node.js 24.21.0; installing @sap/cds means
accepting the SAP Developer License Agreement, as described on CAP Getting Started.
namespace demo;
entity Claims {
key claim_id : Integer;
employee_id : String(8);
status : String(1);
amount : Decimal(9,2);
}
using { demo } from '../db/schema';
service ClaimService {
entity Claims as projection on demo.Claims;
}
claim_id,employee_id,status,amount
1001,E1001,N,120.50
1002,E1002,A,89.00
1003,E1001,R,310.75
1004,E1003,N,45.20
Source: db/schema.cds, srv/claim-service.cds and db/data/demo-Claims.csv of the lab’s CAP project (run with cds-serve), model language as on CAP Getting Started
Started with the CAP runtime, the service is mounted at /odata/v4/claim, the path in the manifest. The log of the CAP
server for one run of the app shows what the OData model asked for. It sends its first request for the metadata
document, then batches the data requests.
[odata] - GET /odata/v4/claim/$metadata { 'sap-language': 'EN' }
[odata] - POST /odata/v4/claim/$batch
[odata] - > GET /Claims {
'$orderby': 'claim_id',
'$select': 'amount,claim_id,employee_id,status',
'$skip': '0',
'$top': '100'
}
[odata] - POST /odata/v4/claim/$batch
[odata] - > GET /Claims(1003) { '$select': 'amount,claim_id,employee_id' }
Source: real output of the CAP server while the lab app showed the list and then claim 1003 (shortened: other log lines are left out), model behavior per Model Instantiation and Data Access
The list request carries the sorter as $orderby, the paging window as $skip and $top, and a $select that names only
the four properties that the table’s cells bind. The detail request for claim 1003 asks for three properties, because the
detail view does not bind status: the autoExpandSelect setting derives the field list from the bindings, so the service
is never asked for more than the screen shows. The OData model also groups requests into $batch calls by itself.
The app is served on port 8127 and the service on port 4127, and a browser only lets a page call its own origin without
extra permission, so the UI5 server of the lab forwards every request that starts with /odata to the CAP server (see
the UI5 Tooling section). The model therefore uses the relative service URL /odata/v4/claim/ of the manifest.
Internationalization: i18n
The texts of an app live in a properties file, one key=value pair per line, and the views refer to them by key. This
is called internationalization, shortened to i18n. A translation is a second file with the language in its name.
appTitle=Expense Claims
listTitle=My claims
detailTitle=Claim details
colClaim=Claim
colEmployee=Employee
colStatus=Status
colAmount=Amount
backButton=Back to the list
greeting=Hello {0}, you have {1} claims
Source: i18n/i18n.properties of the lab project (run; i18n_en.properties holds the same lines), see Resource Model
The manifest declares the resource model with bundleName demo.claims.i18n.i18n, and a view reads a text with
{i18n>listTitle}. In code, getResourceBundle().getText("greeting", ["Alice", count]) replaces {0} and {1}, as the
controller above does. The model asks the browser for the language file that matches the user, here i18n/i18n_en.properties
(the lab’s network log shows that request), and falls back to the manifest’s fallbackLocale. With only i18n.properties
and no file for the fallback language, the UI5 server’s manifest enhancer printed the warning that the generated supported
locales do not contain the default fallback locale en, which the file i18n_en.properties and the two manifest settings
remove. Keep every text a user can read in the properties file and never in the XML, so that a translator never has to
open the code.
Routing
Routing connects the URL of the page to a screen. The manifest’s routing part has three lists. The config holds the
defaults for all routes: the router class, that the targets are views, where the view files are (path), the control
that holds the screens (controlId app, the App of the shell) and the aggregation they are added to (pages). A
route has a name and a pattern, the part of the URL after the #; the pattern claims/{claimId} has a parameter. A
target says which view to show. The Routing Configuration page of the SDK describes each property.
The app is single-page: the browser never loads a new document; the router changes what the App control shows when the
part after # changes. The three ways to move are all visible in the lab. The controller of the list calls
navTo("detail", { claimId }), which sets the URL to #/claims/1003. The detail controller listens with
attachPatternMatched and binds the view to /Claims(1003). And typing #/claims/1004 into the address bar shows the
detail of claim 1004 directly, because the router reads the URL on start. Because the URL is the state, a user can
bookmark or send a detail screen, which is why a route parameter is better than keeping the selected claim in memory.
UI5 Tooling
UI5 Tooling, called UI5 CLI in its documentation, is the command line tool for developing a UI5 app. It is an npm
package, @ui5/cli, and its configuration file is ui5.yaml. It does three jobs: it serves the app during development
with the framework libraries resolved for you, it builds an optimized package, and it downloads the framework libraries
that the app needs from npm into a cache folder under the home directory. The lab uses version 4.0.73, which was the
tooling version tested on 2026-11-13.
specVersion: "4.0"
metadata:
name: demo.claims
type: application
framework:
name: OpenUI5
version: "1.154.0"
libraries:
- name: sap.m
- name: sap.ui.core
- name: sap.ui.layout
- name: themelib_sap_horizon
server:
customMiddleware:
- name: odata-proxy
afterMiddleware: compression
configuration:
prefix: /odata
target: http://localhost:4127
---
specVersion: "4.0"
kind: extension
type: server-middleware
metadata:
name: odata-proxy
middleware:
path: lib/odata-proxy.js
Source: ui5.yaml of the lab project (run), see UI5 CLI
The framework section names the edition (OpenUI5), the version and the libraries, and the libraries are listed only
here: the lab showed that listing them also in package.json stops the server with the error "Duplicate framework
dependency definition(s)". The server and extension parts register a small middleware that forwards /odata requests,
the forwarding mentioned above. It is a lab device, not a part of UI5: the file lib/odata-proxy.js is about twenty
lines of Node.js, listed next.
import http from "node:http";
// Forwards every request whose path starts with the configured prefix to the CAP server.
export default function ({ options }) {
const target = new URL(options.configuration.target);
const prefix = options.configuration.prefix;
return (req, res, next) => {
if (!req.url.startsWith(prefix)) {
return next();
}
const proxied = http.request(
{ host: target.hostname, port: target.port, path: req.url, method: req.method, headers: req.headers },
(answer) => {
res.writeHead(answer.statusCode, answer.headers);
answer.pipe(res);
}
);
proxied.on("error", next);
req.pipe(proxied);
};
}
Source: lib/odata-proxy.js of the lab project (run; the package.json of the UI5 project sets "type": "module"), extension type per UI5 CLI
The commands that were run, from the project folder, with their output:
npx ui5 --version
npx ui5 serve --port 8127
4.0.73
info graph:helpers:ui5Framework Using OpenUI5 version: 1.154.0
Server started
URL: http://localhost:8127
Source: real output of ui5 --version and ui5 serve --port 8127 (UI5 CLI 4.0.73, shortened: warnings about the module type of the middleware file, fixed by "type": "module", are left out), see UI5 CLI
ui5 serve serves the folder webapp at the root and the framework at /resources, which is why index.html can say
src="resources/sap-ui-core.js" without the library being in the project. ui5 build writes the optimized app to a
folder.
npx ui5 build --dest ../dist
info ProjectBuilder Preparing build for project demo.claims
info Project 1 of 1: ❯ Building application project demo.claims...
info demo.claims › Running task escapeNonAsciiCharacters...
info demo.claims › Running task replaceCopyright...
info demo.claims › Running task replaceVersion...
info demo.claims › Running task minify...
info demo.claims › Running task enhanceManifest...
info demo.claims › Running task generateFlexChangesBundle...
info demo.claims › Running task generateComponentPreload...
info ProjectBuilder Build succeeded in 91 ms
Source: real output of ui5 build --dest ../dist (shortened: the target folder line and the cleanup line are left out), see UI5 CLI
The result contains Component-preload.js, one file with all the modules and the views of the app so that the browser
makes one request instead of dozens, and Component.js with its source map. Deploying the build to SAP BTP or to the
ABAP repository of an SAP system needs an SAP BTP account or an SAP system; not run here.
The result in the browser
With the CAP server on port 4127 and ui5 serve on port 8127, the app was opened at
http://localhost:8127/index.html?sap-ui-language=en in a browser, a click was simulated on the third row and then on
the back button. The text of the rendered pages, read from the browser, was the following.
List page: My claims Hello Alice, you have 4 claims
Claim Employee Status Amount
1001 E1001 New 120.50 EUR
1002 E1002 Approved 89.00 EUR
1003 E1001 Rejected 310.75 EUR
1004 E1003 New 45.20 EUR
After the click on the third row, the URL ended in #/claims/1003:
Detail page: Claim details Claim 1003 Employee E1001 Amount 310.75
After the back button the URL ended in # (the list route again)
Source: text read from the rendered page of the lab app (OpenUI5 1.154.0, ?sap-ui-language=en), table layout condensed from the page text
The same page opened in the Spanish browser of the lab showed 1.001 and 120,50: the OData types format numbers by the
user’s language, which is the reason to bind with a type instead of formatting in code.
Fiori elements and freestyle apps
The app above is a freestyle app: you write the views and controllers. SAP Fiori elements, the next topic, produces standard screens such as a list report and an object page from annotations on a service, with no view code. A freestyle app gives you total control and total responsibility; Fiori elements gives you the standard SAP layout with far less code. Use Fiori elements for standard transactional apps and keep freestyle for screens that do not fit a floorplan. The page on SAP Fiori elements, the one on the SAP Fiori design guidelines and the one on testing UI5 apps follow in this section.
Where to practice
The UI5 Walkthrough on GitHub Pages builds a complete app from scratch in steps, each step a runnable app, and the same repository holds the deep-dive tutorials on data binding, navigation and routing, and OData V4. Every tutorial is available in JavaScript and in TypeScript. The README of the UI5 tutorials repository describes the learning path and states the Apache-2.0 license. TypeScript is an option for UI5 apps; the examples on this page use JavaScript.
Summary
-
UI5 comes as SAPUI5 (shipped by SAP) and OpenUI5 (open source, Apache-2.0); this page was run with OpenUI5 1.154.0, the same version number as the latest SAPUI5 1.154 (2611), and uses only libraries that exist in both.
-
An app is a component with a
manifest.jsonthat declares models, libraries and routes; code loads as modules withsap.ui.define. -
A view is XML, a controller is JavaScript, a model holds data; data binding in curly braces connects them, and
data-sap-ui-compat-version="edge"is needed for the full binding syntax. -
The OData V4 model with
autoExpandSelectasks the service only for the fields the views bind and needsoperationMode"Server"for list sorting. -
Texts belong in
i18nfiles and navigation in routes, so that screens can be translated and bookmarked. -
The
ui5command (UI5 CLI) serves the app with the framework resolved from npm and builds a preloaded package.
Try it
To do this by hand, follow the guide Your First SAPUI5 App: it builds a small SAPUI5 app that reads a CAP OData service.