Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
rauf_shaikh
Active Participant

Problem:

Many times we need to include an OData service which is common for many applications.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 distinguish between 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(sap.ui.getCore().getModel("secondModel"));




Property Binding :


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




Regards,

Rauf

1 Comment
Labels in this area