How to Get the Context of a Selected Item in a Detail View in SAP UI5?

For example, you have a master-detail application. When you click on a list item in the master view, then the detail view opens with the data of the selected item.

SAP UI5 master-detail application.
SAP UI5 master-detail view application.

Now you would like to get the data from the model of the selected item that is displayed in the detail view. For example, to validate the data of an edit form for the selected item against the current data of the selected item in the model to check if any data has been changed before saving.

You can easily get the context of the selected item of the detail view through the binding context of the view. The binding context has a method called getObject() that gets you the data of the detail view’s and thus the in the master view selected item.

// in your detail view's controller
...

// get the detail view's binding context
var oBindingContext = this.getView().getBindingContext();

// get the detail view's and thus
// in the master view selected item
var oSelectedItemData = oBindingContext.getObject();

...
No Comments

Get Exclusive SAP Tips

Learn about exclusive SAP tips and insights that are only shared with the private newsletter subscribers.

Will SAP UI5 replace the SAP Web UI?

Result

Essential Ressources

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu