cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Two-Way Binding with createEntry SAPUI5

0 Likes
4,205

I am trying to use Two-Way binding with a v2 OData model. In the route matched of the create view I have the following code.


this.getOwnerComponent().oWhenMetadataIsLoaded.then(function() {

  var oEntry = oView.getModel().createEntry("/ContactCollection");

  oView.setBindingContext(oEntry);

}.bind(this));

  }.bind(this));

At runtime i call the screen and update a value in the create view that is "bound" to the model.

Then in my save function I have been executing the following line in the debugger.


this.getView().getBindingContext().getObject()

The output is a blank entity will all properties set to "undefined".

While searching I found this page

So i implemented line


oView.getModel().setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay);

in the route matched function above with same results.

I have also tried using


oView.unbindElement();

from the discussion here

Any help would be appreciated.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Likes
  1. oView.getModel().setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay); 


Did you try setting the model's default binding mode when it was created instead of in the view?


0 Likes

This worked. I passed in the default binding mode on create to be set to TwoWay using the documentation found here.

Not sure why the function call did not work.

Answers (1)

Answers (1)

junwu
SAP Champion
SAP Champion
0 Likes

how you store the model? with name?

0 Likes

I am using an unnamed model so my binding looks like.


value="{path :'firstName',type: 'sap.ui.model.odata.type.String'}"

junwu
SAP Champion
SAP Champion
0 Likes

when you call

  1. oView.getModel().setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay);  ? before setting binding context?or after?
0 Likes

I did. When I tried it it looked like.


this.getOwnerComponent().oWhenMetadataIsLoaded.then(function() {

  oView.getModel().setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay);

  var oEntry = oView.getModel().createEntry("ContactCollection");

  oView.setBindingContext(oEntry);

});

  }.bind(this));

But still did not work