Show TOC

Assigning the Model to the UILocate this document in the navigation structure

The model instance must be assigned to the UI, that is, the framework must know about the model instance, before you can bind controls to this model instance.

Context

SAPUI5 provides a flexible and modularized concept in which you can not only define one model for your applications, but define different areas in your application with different models and assign single controls to a model. You can also define nested models, for example, a JSON model defined for the application and an OData model for a table control contained in the application.

In order to find the model it should bind to, the control looks up the parent hierarchy until it finds a control or UI area that has an assigned model. A control can only bind to one model, so if you have a container control with an assigned model, all controls contained in this container can only see the local model of the container and are no longer able to bind to the global model.

Procedure

Choose one of the following options:
  • You can define a global model that can be accessed by all controls from all UI areas by using the setModel method on the SAPUI5 core object. This is useful for simple form applications or demo applications.

    sap.ui.getCore().setModel(oModel);
  • You can also define a specific model for sections within a UI area, for example, inside a panel or for a table control. In this case, you can use the setModel method available on any control:

    var oTable = sap.ui.getCore().byId("table");
    oTable.setModel(oModel);