Skip to Content

Multiple Models/BindingContexts in a UI control

Hi,

I am doing some R&D on the Model and Binding support for UI controls. I see the following structure for UI control.

My question is multi fold.

1. I am able to set more than 1 Model for a UI control. If in the console I drill down on the oModels sub-object of the UI Control, I can see an array of the models that I had set, each model having its own name. e.g.

var oModel1 = new sap.ui.model.json.JSONModel(data1);
  var oModel2 = new sap.ui.model.json.JSONModel(data2);
  var btn = new sap.ui.commons.Button("mybtn",{text:"TestButton",press:function(){alert('hello');}});
  btn.setModel(oModel1,"sh1"); //model1
  btn.setModel(oModel2,"sh2"); //model2


How do I actually make use of these 2 models simultaneously on the same instance of the control?

2. The exact same thing for BindingContexts or for that matter mElementBindingContexts. In the sub-object oBindingContexts e.g., I was able to set multiple binding contexts but was not able to use either of them fruitfully. I was being able to use the binding context successfully only when the ui control had 1 binding context only. Similarly the mElementBindingContexts.

My question is can we have multiple models, and therefore multiple binding contexts for a UI control. I know multiple models or binding contexts for a button as shown in the example does not make much sense but say a Matrix Layout which can have its hierarchy of children. Can we set multiple models and binding contexts in a MatrixLayout e.g. and then use the relative paths in the hierarchy successfully?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Jan 12, 2016 at 03:32 PM

    Yes. Here's an example taken from a Web IDE generate app using three models, an odata, and two json models, device and i18n.

    <List growing="true" growingScrollToLoad="true" id="list" items="{/Products}" mode="{device>/listMode}"
      noDataText="{i18n>masterListNoDataText}" select="onSelect">
      <items>
      <ObjectListItem number="{Price}" numberUnit="{Rating}" press="onSelect" title="{Name}" type="{device>/listItemType}"></ObjectListItem>
      </items>
      </List>
      </content>
    

    Regards,

    Jamie

    SAP - Technology RIG

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.