Hello Community,
I'm working on a simple webmask which allows a user to do CRUD operations on a game library (which contains some names of Computer Games).
Technical Background:
Problem Description:
While Read, Insert and Delete work as expected, I have trouble using the update-Method for the oModel which is based on my xsodata service that has been configured in the manifest.json.
The situation: Whenever I fire the oModel.update call, the update does not use HTTP-method "PUT", but "POST" instead. Of course the Webservice then returns the following error message:
The URI is not valid for POST operation. The URI must point to an entity set for POST operations.
My request:
POST /xsodata/getGames.xsodata/games(17) HTTP/1.1 Content-Length: 35 Host: xsa.realcore.local:51059 Content-Type: application/json { "ID": 17, "GAME": "Quake 2" }
Of course this is wrong, but I do not have any influence on the http method that has been configured to the update-method so far:
this._gameService = this._ownerComponent.getModel("games"); this._gameService.setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay); this._gameService.setRefreshAfterChange(true); var that = this; this._gameService.setHeaders({ "content-type": "application/json;charset=utf-8" }); this._gameService.update("/games("+gameObjectToSave.ID+")", gameObjectToSave, { success: function() { that._readGames(); that._oGameLibrary.refresh(); }, error: function(e) { console.log(e); } });
Manifest.json:
"dataSources": { "games": { "uri": "/xsodata/getGames.xsodata", "type": "oData", "settings": { "odataVersion": "2.0" } } } .... "games": { "dataSource": "games", "type": "sap.ui.model.odata.v2.ODataModel", "preload": true, "settings": { "odataVersion": "2.0", "useBatch" : false } } ....
Possible, but bad way to solve this:
One way to solve this issue is to use a deprecated version of the ODataModel:
"type": "sap.ui.model.odata.ODataModel",
(Infos about the deprecation can be found in the api-documentation of openui5.)
But I would like to use ODataModel Version 2. In V1 it somehow works and the update is using the "PUT" method as expected.
Any ideas?
Kind regards
Marc