Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9656

Re: (open) UI5 Mockserver combined with ODataModel problem

$
0
0

Hi Tin

Missing context into your code ill point you to the Sap.m Cart test app to see how the MockServer works with an ODataModel

 

you'll find the app in the following folder

C:\<ui5sdk>\test-resources\sap\m\demokit\cart\model

 

first off you need to

- create a model folder

- add a metadata.xml, use your live services as a template

http://services.odata.org/Northwind/Northwind.svc/$metadata

- for each of the entities you want to mock create an <entity>.json file

eg Products.json =

http://services.odata.org/Northwind/Northwind.svc/Products?$format=application/json;odata=nometadata

 

in your code you need to set up the mockserver to fake your service

var url="http://services.odata.org/Northwind/Northwind.svc/";

jQuery.sap.require("sap.ui.core.util.MockServer-dbg");

 

if (mock === true ){

  varoMockServer=newsap.ui.core.util.MockServer({

        rootUri:url

    });

    oMockServer.simulate("model/metadata.xml","model/");

    oMockServer.start();

}

varoModel=newsap.ui.model.odata.ODataModel(url,true);

sap.ui.getCore().setModel(oModel);

 

fyi - ODataModel.read is a bit of an anti pattern as it doesn't add data to the context for binding, this is the real power of the ODataModel, you should really bind to something like a tables list/items or a controls property

 

hth

jsp


Viewing all articles
Browse latest Browse all 9656

Trending Articles



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