SAPUI5: Retrieve model object in controller

Well your approach isn't to far off and is indeed pretty much the same as hirses.

The point is the binding does not contain "just" the bound model object. It contains the information about model, path to the "bound object" and context. These can be retrieved from the binding. To access the "bound object" you then have basically two paths available.

Get the model and path from the binding and access the "bound object" via the model: (this is what you and hirse outlined)

var path = this.getView().getElementBinding('contracts').sPath;
var boundObject = this.getView().getModel('contracts').getProperty(path);

Or get the context and path and access the "bound object" that way:

var context = this.getView().getElementBinding('contracts').oContext;
var boundObject = context.getProperty(context.getPath());

Without having done to much research into this I would prefer the second option. It just seems more along the line of how the context binding is intended.


I would have thought,

this.getView().getModel('contracts')

gives you the Model Object (as in an object of type sap.ui.model.Model or subclass).

If you are referring to the data in the Model, you can use the following:

this.getView().getModel('contracts').getProperty("/")