Quantcast
Channel: SAPUI5 Developer Center
Viewing all articles
Browse latest Browse all 789

Multi Model Support and Binding For OData Services

$
0
0

Problem:

 

Many times we need to include an OData service which is common for many application.In this scenario instead re writing the OData

service again we should create more than one model.

 

Create Main OData Model and set it globally :

 

this.metadataUrl = "proxy/sap/opu/odata/sap/ZMM_MOBILE_MATERIAL_SRV/";   sap.ca.common.uilib.Ajax.registerModelUrl(  "sap/opu/odata/sap/ZMM_MOBILE_MATERIAL_SRV/",  "proxy/sap/opu/odata/sap/ZMM_MOBILE_MATERIAL_SRV/");
this.oDataModel = new sap.ui.model.odata.ODataModel(this.metadataUrl,true);
this.oDataModel.setCountSupported(false);
sap.ui.getCore().setModel(this.oDataModel,"mainModel");

 

Create Second OData Model :

 

this.metadataUrl2 = "proxy/sap/opu/odata/sap/Z_NEW_ODATA_SRV/";   sap.ca.common.uilib.Ajax.registerModelUrl(  "sap/opu/odata/sap/Z_NEW_ODATA_SRV/",  "proxy/sap/opu/odata/sap/Z_NEW_ODATA_SRV/");
this.oDataModel2 = new sap.ui.model.odata.ODataModel(this.metadataUrl2,true);
this.oDataModel2.setCountSupported(false);
sap.ui.getCore().setModel(this.oDataModel2,"secondModel");

 

 

Explanation:

sap.ui.getCore().setModel(this.oDataModel,"mainModel");
sap.ui.getCore().setModel(this.oDataModel,"secondModel");

 

The above line will set OData models to the core of the application.To distiguish bwetween both of them in our application we can give

modelNames(mainModel,secondModel) while setting it.

 

Using The Models:

Say you want to set the "secondModel" to a list control :

 

this.getView().byId("list").setModel(this.oDataModel2);

 

Proprty Binding :

 

<Text text="{mainModel>/name}"/><Text text="{secondModel>/name}"/>

Regards,

Rauf


Viewing all articles
Browse latest Browse all 789

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>