SAPUI5 and Fiori Tools Part 1: MVC, Models, Views and Controllers
Free sample lesson · open to everyone
Learn how a freestyle SAPUI5 app is structured — Component. js and manifest. json describe the app, the View declares UI in XML, the Model holds data, and the Controller wires user interaction together — and understand when freestyle UI5 is the right choice instead of Fiori Elements.
In this lessonShow sectionsHide sections
Visual overview
Expert visual walkthrough
MVC, Models, Views and Controllers
SAPUI5 and SAP Fiori Tools · Chapter-specific technical teaching map
Architecture hierarchy
App view
Controller / model
OData binding
Backend service
Tutor's chapter takeaway
Learn how a freestyle SAPUI5 app is structured — Component.js and manifest.json describe the app, the View declares UI in XML, the Model holds data, and the Controller wires user interaction together — and understand when freestyle UI5 is the right choice instead of…
In a real project
A freestyle app for approving purchase requests put every button handler, OData call and status-text rule directly into Main.controller.js. After six months the controller had grown past 1,500 lines, and a developer asked to…
Watch out for
• Writing all interaction and business logic into one controller instead of delegating to models, formatters and the backend — it is the fastest way to get something on screen, but it does not scale; keep controllers to event…
The situation: a real project scenario
A freestyle app for approving purchase requests put every button handler, OData call and status-text rule directly into Main.controller.js. After six months the controller had grown past 1,500 lines, and a developer asked to add a "reject with reason" dialog could not find where the approval rule actually lived. Splitting the controller into thin event handlers, moving display logic into a formatter, and keeping the approval rule in the RAP behavior implementation turned the next change into a one-line call instead of a day of reading someone else's controller.
Explanation
In MVC, the Model holds data, the View describes the UI in XML, and the Controller handles interaction logic. An application's Component.js and manifest.json together describe the app as a whole — its models, routing and dependencies. Views bind to models declaratively, and controllers should stay thin. Freestyle UI5 is worth choosing only when Fiori Elements genuinely cannot fulfill the requirement.
This complete series covers SAPUI5 across seven parts: MVC and application architecture; SAP Fiori tools setup and project generation; models and data binding; routing, navigation, fragments and dialogs; OData V4 CRUD and backend integration; debugging, testing and performance; and deployment and the production lifecycle.
SAPUI5 still matters because, while Fiori Elements is excellent when a metadata-driven floorplan fits the requirement, SAPUI5 remains important whenever you need a freestyle application, custom interaction, special visualization, or deeper frontend control. It's worth being disciplined here — freestyle UI5 shouldn't be chosen simply because it feels more flexible, since more custom UI code also means more code to test and maintain.
MVC can be summarized in one sentence: the Model holds data, the View describes the UI, and the Controller handles interaction and orchestration. That separation is what makes a UI easier to understand and test.
A modern SAPUI5 application normally has an application component paired with a manifest. The manifest describes configuration such as the application ID, models and data sources, routing, dependencies, and device or resource settings — and it's worth keeping configuration declarative wherever the framework supports it.
On models: common concepts include a JSON model for local or client-side data, a resource model for translated text, and an OData model for backend service data. A model isn't a database — it's the client-side abstraction that controls and bindings actually work against.
Data binding means that, instead of manually copying values into every UI control, the UI is bound directly to model paths — for example, an Input control's value might be bound to "{/customer/name}". When the model changes, the binding keeps the UI synchronized according to whatever binding mode is in effect.
UI5 controls expose properties, events and aggregations. A table, for instance, aggregates items; a page aggregates content; a button raises a press event. The goal is to understand the control API rather than manipulate the DOM directly.
A controller's job is to coordinate UI behavior, not to become a 3,000-line business engine. Good controller tasks include event handling, navigation, model orchestration, delegating formatting, and calling reusable services — backend business validation should stay on the backend, not migrate into the controller.
By the end of this you should be able to explain the runtime path end to end: Component leads to manifest, which leads to model, which leads to view binding, which leads to a controller event, which leads to a call into the service or backend.
Common mistakes to avoid include writing all logic into one controller, manipulating the HTML DOM directly, hard-coding texts instead of using i18n, choosing freestyle UI5 when Fiori Elements already fits, and duplicating backend business rules in JavaScript.
As an interview-ready summary: SAPUI5 is a component-based JavaScript UI framework. Freestyle apps are structured with manifest-driven configuration, MVC, models and declarative data binding, with controllers orchestrating UI behavior while authoritative business rules remain in backend services.
Code example
// ===== Component.js - the app entry point =====sap.ui.define(["sap/ui/core/UIComponent"], function (UIComponent) { "use strict"; return UIComponent.extend("zpurchreq.Component", { metadata: { manifest: "json" }, // configuration comes from manifest.json init: function () { UIComponent.prototype.init.apply(this, arguments); this.getRouter().initialize(); // start routing (Part 4) } });}); // ===== manifest.json (excerpt) =====// "sap.app": { "id": "zpurchreq", "i18n": "i18n/i18n.properties", ... }// "sap.ui5": { "rootView": { "viewName": "zpurchreq.view.App", "type": "XML" },// "models": { "i18n": { "type": "sap.ui.model.resource.ResourceModel",// "settings": { "bundleName": "zpurchreq.i18n.i18n" } } } } <!-- ===== view/Main.view.xml - the View (UI only) ===== --><mvc:View controllerName="zpurchreq.controller.Main" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"> <Page title="{i18n>appTitle}"> <Input value="{/request/description}" placeholder="{i18n>description}" /> <Button text="{i18n>save}" type="Emphasized" press=".onSave" /> </Page></mvc:View> // ===== controller/Main.controller.js - the Controller (interaction) =====sap.ui.define(["sap/ui/core/mvc/Controller", "sap/ui/model/json/JSONModel", "sap/m/MessageToast"], function (Controller, JSONModel, MessageToast) { "use strict"; return Controller.extend("zpurchreq.controller.Main", { onInit: function () { // the Model: data for this view this.getView().setModel(new JSONModel({ request: { description: "" } })); }, onSave: function () { const sText = this.getView().getModel().getProperty("/request/description"); MessageToast.show("Saved: " + sText); // real apps save via the OData model (Part 5) } });}); # ===== i18n/i18n.properties =====# appTitle=Purchase Requests# description=Description# save=SaveWatch out
Common mistakes
- Writing all interaction and business logic into one controller instead of delegating to models, formatters and the backend — it is the fastest way to get something on screen, but it does not scale; keep controllers to event handling, navigation and orchestration only.
- Manipulating the DOM or rendered HTML directly (e.g. jQuery against control internals) instead of using the control's own API — breaks silently on UI5 version upgrades and is hard to test.
- Hard-coding UI text instead of using i18n resource bundles from the first view — turns every text change or translation into a code change and a transport.
- Duplicating backend business validation in JavaScript "for faster feedback" — creates two sources of truth that drift apart; keep the authoritative rule in the backend (RAP) and treat any frontend check as a UX shortcut only.
- Reaching for freestyle UI5 by default because it "feels more flexible" when a Fiori Elements floorplan would already cover the requirement — buys ongoing maintenance cost for no business benefit.
Do this
Best practices
- Keep controllers thin — event handling, navigation and orchestration only; push formatting to formatters and business rules to the backend.
- Drive app configuration (models, routing, dependencies, device settings) through manifest.json rather than code, so tooling and other developers can read it declaratively.
- Externalize every user-facing string to i18n.properties from the first view, not as a later cleanup.
- Prefer declarative data binding over imperative getControlById().setValue() calls — it scales better as the view grows and survives re-renders.
- Default to Fiori Elements; choose freestyle SAPUI5 only when a specific interaction or visualization genuinely cannot be expressed through annotations.
In the interview
Interview angle
Questions: "Explain MVC in SAPUI5", "What goes in Component.js versus manifest.json?", "Why use data binding instead of calling setText() in a click handler?", "When would you choose freestyle UI5 over Fiori Elements?"
Strong answer: Model holds data, View declares UI in XML, Controller handles interaction; Component.js bootstraps the app and reads its configuration (models, routing, dependencies) from manifest.json so configuration stays declarative and tool-readable; binding keeps the UI synchronized with the model automatically instead of scattering manual get/set calls across handlers; freestyle UI5 is justified only when a metadata-driven floorplan genuinely cannot deliver the required interaction — picking it as a default is a maintenance cost with no payoff. A weak answer treats MVC as just "three folders" without explaining what actually moves data to the screen.
Practice this lesson
Quick check
0 of 3 questions attempted
Question 1 of 3
What is the main purpose of manifest.json in a SAPUI5 app?
Question 2 of 3
Which practice makes a freestyle SAPUI5 app hard to maintain?
Question 3 of 3
In SAPUI5 MVC, where should the event handler for a Save button be implemented?
Practise this in an interview
Answer in your own words and get instant feedback, the way an interviewer would judge it.
1Explain MVC in SAPUI5 and the role of Component.js and manifest.json.
2A freestyle app has 2,000-line controllers mixing UI, data and business logic. How do you restructure it?
See it in code
Each example starts from a requirement, shows the design, then the code step by step with a plain-language explanation of every part.
Was this lesson helpful?
Keep exploring
Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.