Working With Odata Services: Week 2 Unit 6
Working With Odata Services: Week 2 Unit 6
Working With Odata Services: Week 2 Unit 6
Table of Contents
Preview
webapp/Component.js
sap.ui.define([
"sap/ui/core/UIComponent"
], function (UIComponent) {
"use strict";
return UIComponent.extend("opensap.myapp.Component", {
metadata : {
manifest: "json"
},
init : function () {
// call the init function of the parent
UIComponent.prototype.init.apply(this, arguments);
});
});
In the init method of the component, we add a single line that manually turns off batch processing to
be able to debug calls from the ODataModel to the server easily. By default, batch processing is
turned on in SAPUI5, so all calls that would otherwise be sent to a server in a single request are
composed to a batch request that combines multiple requests.
This is a great performance boost, especially when network latency is high, but also makes debugging
hard. That is why we manually turn off batch processing in our app so that you can analyze how
changes in your app - for example adding or removing filters - influence the calls sent to the backend
service.
Copyright/Trademark
openSAP – Developing Web Apps with SAPUI5
webapp/view/App.view.xml
<mvc:View>
…
<List
id="productsList"
items="{
path: '/ProductSet',
parameters : {
expand: 'ToSupplier'
},
sorter : {
path : 'Category',
group : true
}
}"
growing="true"
growingThreshold="5"
growingScrollToLoad="false">
<headerToolbar>
<Toolbar>
<Title text="{i18n>productListTitle}"/>
<ToolbarSpacer/>
<SearchField width="50%"
search="onFilterProducts"/>
</Toolbar>
</headerToolbar>
<items>
<ObjectListItem
title="{Name}"
number="{Price}"
numberState="{= ${Price} > 500 ? 'Error' :
'Success'}"
intro="{ProductID}"
press="onItemSelected"
type="Active">
<firstStatus>
<ObjectStatus text="{
parts: [
{path: 'WeightUnit'},
{path: 'WeightMeasure'}
],
formatter : '.formatter.delivery'
}"/>
</firstStatus>
<secondStatus>
<ObjectStatus
title="{i18n>statusDeliveryFrom}"
text="{ToSupplier/Address/City}"/>
</secondStatus>
</ObjectListItem>
</items>
</List>
…
</mvc:View>
In this step we want to use the OData query parameter $expand to be able to display additional
information from a related entity.
Copyright/Trademark
openSAP – Developing Web Apps with SAPUI5
First we have to add the parameter to the list binding. For that, we use the parameters setting in the
binding and pass the ToSupplier navigation property to this parameter. We can now use properties
from this entity using relative paths. We add the secondStatus aggregation to our list item and add
an sap.m.ObjectStatus control into it. We bind its property text to the City property in the
BusinessPartner entity of the service, which is the target type of navigation property ToSupplier.
webapp/i18n/i18n.properties
…
# Data Binding Content
productListTitle=Products
...
statusDeliveryFrom=From
…
Related Information
OData.org
Copyright/Trademark
openSAP – Developing Web Apps with SAPUI5
Note:
This workaround is only applicable if you are using the mock server as described in week 2 unit 1. It
will create random test data in your app if the service connection is too slow during these exercises.
The MockServer will be explained later in the course in more detail and would be set up a bit
differently in a real project.
webapp/metadata.xml
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0"
xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns:sap="http://www.sap.com/Protocols/SAPData">
<edmx:DataServices m:DataServiceVersion="2.0">
<Schema
xmlns="http://schemas.microsoft.com/ado/2008/09/edm"
Namespace="/IWBEP/GWSAMPLE_BASIC"
xml:lang="en"
sap:schema-version="1">
<EntityType Name="BusinessPartner" sap:content-version="1">
<Key>
<PropertyRef Name="BusinessPartnerID"/>
</Key>
<Property Name="Address" Type="/IWBEP/GWSAMPLE_BASIC.CT_Address"
Nullable="false"/>
<Property Name="BusinessPartnerID" Type="Edm.String"
Nullable="false" MaxLength="10" sap:label="Geschäftspartner-ID"
sap:creatable="false" sap:updatable="false"/>
<Property Name="CompanyName" Type="Edm.String" Nullable="false"
MaxLength="80" sap:label="Firma"/>
<Property Name="WebAddress" Type="Edm.String" sap:sortable="false"
sap:filterable="false" sap:semantics="url"/>
<Property Name="EmailAddress" Type="Edm.String" Nullable="false"
MaxLength="255" sap:label="E-Mail" sap:semantics="email"/>
<Property Name="PhoneNumber" Type="Edm.String" MaxLength="30"
sap:label="Telefonnr." sap:semantics="tel"/>
<Property Name="FaxNumber" Type="Edm.String" MaxLength="30"/>
<Property Name="LegalForm" Type="Edm.String" MaxLength="10"
sap:label="Rechtsform"/>
<Property Name="CurrencyCode" Type="Edm.String" Nullable="false"
MaxLength="5" sap:label="Währungscode" sap:semantics="currency-code"/>
<Property Name="BusinessPartnerRole" Type="Edm.String"
Nullable="false" MaxLength="3" sap:label="GeschPartnRolle"/>
<Property Name="CreatedAt" Type="Edm.DateTime" Precision="7"
sap:label="Zeitstempel" sap:creatable="false" sap:updatable="false"/>
<Property Name="ChangedAt" Type="Edm.DateTime" Precision="7"
ConcurrencyMode="Fixed" sap:label="Zeitstempel" sap:creatable="false"
sap:updatable="false"/>
</EntityType>
<EntityType Name="Product">
<Key>
<PropertyRef Name="ProductID"/>
Copyright/Trademark
openSAP – Developing Web Apps with SAPUI5
</Key>
<Property Name="ProductID" Type="Edm.String" Nullable="false"
MaxLength="10"/>
<Property Name="TypeCode" Type="Edm.String" Nullable="false"
MaxLength="2"/>
<Property Name="Category" Type="Edm.String" Nullable="false"
MaxLength="40"/>
<Property Name="Name" Type="Edm.String" Nullable="false"
MaxLength="255"/>
<Property Name="NameLanguage" Type="Edm.String" MaxLength="2"/>
<Property Name="Description" Type="Edm.String" MaxLength="255"/>
<Property Name="DescriptionLanguage" Type="Edm.String"
MaxLength="2"/>
<Property Name="SupplierID" Type="Edm.String" Nullable="false"
MaxLength="10"/>
<Property Name="SupplierName" Type="Edm.String" MaxLength="80"/>
<Property Name="TaxTarifCode" Type="Edm.Byte" Nullable="false"/>
<Property Name="MeasureUnit" Type="Edm.String" Nullable="false"
MaxLength="3"/>
<Property Name="WeightMeasure" Type="Edm.Decimal" Precision="13"
Scale="3"/>
<Property Name="WeightUnit" Type="Edm.String" MaxLength="3"/>
<Property Name="CurrencyCode" Type="Edm.String" Nullable="false"
MaxLength="5"/>
<Property Name="Price" Type="Edm.Decimal" Precision="16"
Scale="3"/>
<Property Name="Width" Type="Edm.Decimal" Precision="13"
Scale="3"/>
<Property Name="Depth" Type="Edm.Decimal" Precision="13"
Scale="3"/>
<Property Name="Height" Type="Edm.Decimal" Precision="13"
Scale="3"/>
<Property Name="DimUnit" Type="Edm.String" MaxLength="3"
sap:label="Dimension Unit"/>
<Property Name="CreatedAt" Type="Edm.DateTime" Precision="7"/>
<Property Name="ChangedAt" Type="Edm.DateTime" Precision="7"
ConcurrencyMode="Fixed"/>
<NavigationProperty Name="ToSupplier"
Relationship="/IWBEP/GWSAMPLE_BASIC.Assoc_Products_BusinessPartner"
FromRole="FromRole_Assoc_Products_BusinessPartner"
ToRole="ToRole_Assoc_Products_BusinessPartner"/>
</EntityType>
<EntityContainer Name="/IWBEP/GWSAMPLE_BASIC_Entities"
m:IsDefaultEntityContainer="true">
<EntitySet Name="BusinessPartnerSet"
EntityType="/IWBEP/GWSAMPLE_BASIC.BusinessPartner" sap:content-
version="1"/>
<EntitySet Name="ProductSet"
EntityType="/IWBEP/GWSAMPLE_BASIC.Product"/>
<Association Name="Assoc_Products_BusinessPartner" sap:content-
version="1">
<End Type="/IWBEP/GWSAMPLE_BASIC.BusinessPartner"
Multiplicity="1" Role="FromRole_Assoc_BusinessPartner_Products"/>
<End Type="/IWBEP/GWSAMPLE_BASIC.Product" Multiplicity="*"
Role="ToRole_Assoc_BusinessPartner_Products"/>
<ReferentialConstraint>
Copyright/Trademark
openSAP – Developing Web Apps with SAPUI5
<Principal Role="FromRole_Assoc_Products_BusinessPartner">
<PropertyRef Name="SupplierID"/>
</Principal>
<Dependent Role="ToRole_Assoc_Products_BusinessPartner">
<PropertyRef Name="BusinessPartnerID"/>
</Dependent>
</ReferentialConstraint>
</Association>
<AssociationSet Name="Assoc_Products_BusinessPartner_AssocSet"
Association="/IWBEP/GWSAMPLE_BASIC.Assoc_Products_BusinessPartner"
sap:creatable="false" sap:updatable="false" sap:deletable="false"
sap:content-version="1">
<End EntitySet="ProductSet"
Role="FromRole_Assoc_Products_BusinessPartner"/>
<End EntitySet="BusinessPartnerSet"
Role="ToRole_Assoc_Products_BusinessPartner"/>
</AssociationSet>
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
Replace the contents of the file metadata.xml with the updated service interface. The entity
BusinessPartner has been added.
Coding Samples
Any software coding or code lines/strings (“Code”) provided in this documentation are only examples
and are not intended for use in a productive system environment. The Code is only intended to better
explain and visualize the syntax and phrasing rules for certain SAP coding. SAP does not warrant the
correctness or completeness of the Code provided herein and SAP shall not be liable for errors or
damages cause by use of the Code, except where such damages were caused by SAP with intent or
with gross negligence.
Copyright/Trademark