7

I made a Master-Detail application in Web IDE with SAPUI5.

I connected my application to an OData service (V2). The connection parameters have been stored in manifest.json.

I want to prevent my UI5 application from using $batch requests.

I know how to use the following code to disable batch request for a particular request:

var oDataModel = this.getModel(); // sap.ui.model.odata.v2.ODataModel
oDataModel.setUseBatch(false);

But the problem is that I can not use this in onInit function.

Can I set some parameter in manifest.json to disable batch request in general and even when the program is loading it does not use $batch?

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170

3 Answers3

17

You should be able to add parameter useBatch to the settings of your model. According to the documentation (section /sap.ui5/models) these settings will be passed to the constructor.

{
  "sap.ui5": {
    "models": {
      "yourV2ODataModel": {
        "dataSource": "yourDataSource",
        "settings": {
          "useBatch": false
        }
      }
    }
  }
}

The availability of component models in onInit has been discussed here several times. See the application init process to see why they are not available.

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
matbtt
  • 4,230
  • 19
  • 26
0

Well you could to it in the onInit function. But like this:

var oDataModel = this.getOwnerComponent().getModel();

oDataModel.setUseBatch(false);
  • 3
    hi, setting properties of a model that is defined in manifest.json is not considered good idea. imagine the model being replaced by a mockservers model or what not. the correct answer is already given, and is to set the models settings in the manifest.json – Michael Schönbauer Jan 05 '21 at 16:27
0

Go to Component.js

on its "init" method:

this.getModel("yourDesiredModel").setUseBatch(false)
nicolass
  • 526
  • 5
  • 8