Models UI5 1733751798
Models UI5 1733751798
Resource Model
XML Model
In SAP UI5, models are used to bind data to UI elements, enabling a clear
separation of concerns between the UI and the business logic.
Types of Models in SAP UI5
1. JSON Model
• A client-side model used to manage data in JSON format.
• Ideal for small, static, or dynamic data.
• Lightweight and easy to use.
Example Data:
json
2. XML Model
• A client-side model that manages data in XML format.
• Best for scenarios where data is already available in XML format.
Example Data:
xml
3. Resource Model
• Used for managing translatable texts in applications.
• Enables localization by binding UI elements to language-specific texts.
Usage:
• Applications requiring multi-language support.
4. OData Model
• The most commonly used model in SAP UI5 for handling data.
• Allows binding to OData services (Open Data Protocol).
• Supports client-server communication for CRUD operations.
Subtypes:
• OData V2 Model: Works with OData V2 services.
• OData V4 Model: Works with OData V4 services and provides better
performance.
Creating Models: Step-by-Step Guide
Step 1: JSON Model
1. Create the JSON file (data.json):
{
"employees": [
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/model/json/JSONModel"
], function(Controller, JSONModel) {
"use strict";
return Controller.extend("example.controller.Main", {
onInit: function() {
this.getView().setModel(oModel);
});
});
<List items="{/employees}">
</List>
</mvc:View>
<mvc:View xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"> <List items="{/employees}">
<StandardListItem title="{name}" description="{age}" /> </List> </mvc:View>
Follow