Quantcast
Channel: SCN : All Content - SAPUI5 Developer Center
Viewing all articles
Browse latest Browse all 6178

.refresh not working after update and read (odata, xml views)

$
0
0

Hi!

 

I'm really puzzled and have not the faintest idea how to solve this. I hope, the community here might be able to help.

The problem is also somewhat complex, so please bear with me and my lengthy descriptions.

 

I use xml views and the odata model.

The odata structure contains data on a basic level and several collections/entity sets/lists.

In order to get at any data from the server, I need to create an order from certain parameters. This gives me an id. This id I use to read some general data, createBindingContext and setBindingContext.

That all works fine and I get my basic data and all the data from the collections.

But. When I update the model with new information (user input), and read again and call refresh with true, nothing changes in the view, although the data I receive in the callback changed.

 

So, how can I force the xml view to update its bindings?

Do I need to update the bindings manually? And how can I do this, when there is a list involved?

 

In my one page example for testing purposes I do the following (sorry, no working example as the data server is in our development environment and thus not accessible from remote):

The id has already been created in this example. It's called IdentNr.

 

In this example the page title does not change, after pressing a button.

I expect Preset: {modelAuftrag>Schnell} to be different after pressing the button myButton2. But the value does not change. Although oData in the callback in _readAuftrag contains the correct updated value.

 

XML:

<Page title="Title, chosen Preset: {modelAuftrag>Schnell}, Identnr: {modelAuftrag>IdentNr}">

[...there's a list here which does not concern us right now...]

<Button text="Change IdentNr, get new Preset Gestaltete Anzeige - Preset1" press="onButtonPress1" id="myButton1"/>

<Button text="Change IdentNr, get new Preset Angebot gestaltete Anzeige - Preset2" press="onButtonPress2" id="myButton2"/>

 

Controller:

Init:

   var oModelAuftrag = new sap.ui.model.odata.ODataModel(sServiceUrl, true, sUsername, sPassword);

  oView.setModel(oModelAuftrag, "modelAuftrag");

 

  var oModel = oView.getModel('modelAuftrag');

 

  this.IdentNr  = "4711";

  this.Kennung1 = "Preset1";

this.Kennung2 = "Preset2";

 

  this.AuftragBindingPath = "/Orders('" + this.IdentNr + "')";

 

var tmpPath = this.AuftragBindingPath;

oModel.read(tmpPath, null, null, false,

   jQuery.proxy(function(oData, oResponse){

      // success

       this._createBindingContextAuftrag(this.AuftragBindingPath);

     },this),

   jQuery.proxy(function(oData, oResponse){

      // fail

     },this)

);

 

_createBindingContextAuftrag : function(sBindingPath){

   this.getView().getModel('modelAuftrag').createBindingContext(sBindingPath, null, null, jQuery.proxy(function(oContext){

       this.setBindingContext(oContext, 'modelAuftrag');

   }, this.getView()));

},

 

handleUpdateKennung : function(sKennung){

  var sPathUpdate      = "/Presets(IdentNr='" + this.IdentNr +  "',PresetID='" + sKennung + "')";

  var oModel          = this.getView().getModel('modelAuftrag');

 

  var oPayload       = { "IdentNr" : this.IdentNr, "PresetID" :  sKennung };  

  var oEntry        = oPayload;

 

  oModel.update(sPathUpdate,

      oEntry, null,

          jQuery.proxy(function(oData, oResponse){

         // update success

            // oData is null, oResponse should be status code 204

            this._readAuftrag();

          }, this),

          jQuery.proxy(function(oSome, someOther){

         // update failed

          }, this.getView())

  );

}, 

 

_readAuftrag : function(){

var sPath = this.getView().getBindingContext('modelAuftrag').getPath();

this.getView().getModel('modelAuftrag').read(sPath, null, null, false,

      jQuery.proxy(function(oData, oResponse){

          this.AuftragBindingPath = "/Orders('" + this.IdentNr + "')";

          this.getView().getModel('modelAuftrag').refresh(true); // this does not work: no bindings are updated

      }, this),

      jQuery.proxy(function(oError){

      }, this));

},

 

onButtonPress1 : function(oEvent){

this.handleUpdateKennung(this.Preset1);

 

},

onButtonPress2 : function(oEvent){

this.handleUpdateKennung(this.Preset2);

},

 

Many thanks in advance!

 

Regards,

Anja


Viewing all articles
Browse latest Browse all 6178

Trending Articles



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