Multi Model Support and Binding For OData Services
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 :
Regards,
Rauf
New NetWeaver Information at SAP.com
Very Helpfull