cancel
Showing results for 
Search instead for 
Did you mean: 

OdataModel as named Model and databinding

b_deterd2
Active Contributor
0 Kudos

Hello,

When we create an odatamodel (not a named model), the textfield in the view is populated with a value. So everything works fine.

However when we create the odatamodel as a named model there seems to be no way to do a property binding.

Let me give you an example with the "http://services.odata.org/Northwind/Northwind.svc/" service .

Controller:

var oModel = new sap.ui.model.odata.ODataModel("http://services.odata.org/Northwind/Northwind.svc/");

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

View:

var oTf = new sap.ui.commons.TextField('input1');

  oTf.bindElement("/Categories(1)");

  oTf.bindProperty("value", {

     path: "CategoryName"

  });

  return oTf;

However : when we want the odatamodel to be a named model, the value in the textfield is not populated anymore.

Controller:

  var oModel2 = new sap.ui.model.odata.ODataModel("http://services.odata.org/Northwind/Northwind.svc/");

  sap.ui.getCore().setModel(oModel2, "testModel");

View:

  var oTf = new sap.ui.commons.TextField('input1');

  oTf.bindElement("/Categories(1)");

  oTf.bindProperty("value", {

      path: "CategoryName",

      model: "testModel"

  });

  return oTf;

We tried several settings with path like testModel>/Categories(1) but no luck.

Could anyone tell us how to use the oDataModel as a named model with regards to property binding?

Any help will be appreciated.

Regards,

Bert

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Bert,

please try the following:


var oTf = new sap.ui.commons.TextField('input1');

oTf.bindElement("testModel>/Categories(1)"); 

oTf.bindProperty("value", "testModel>CategoryName");

return oTf;

Regards

Stefan

Qualiture
Active Contributor
0 Kudos

Stefan is right.

If you use named models, always remember to prefix any bound value/element/property with the correct named model too.