Skip to Content
Former Member
Nov 03, 2013 at 04:49 PM

How to dynamically bind data to a Controll


Hey guys,

what I actually try to do is to bind data from an oDataModel to a simpleForm. But the difficulty is that I need to bind it dependant on which listItem the User clicks.

So this is my scenario: I have a List with 3 listItems in it. When I click on a listItem a new page should appear with a simpleForm in it, which displays some data from the oDataModel. The page should be the same page everytime I click on a listItem, but the data displayed in the textfield from the simpleForm in this page should change depending on which listItem I click.

So this is my method when i click on a listItems.

onGetInput: function(oEvent){                                                            var allTaskModel =this.getModel("AllTasks");                                                            var getSelectedContext=this.getBindingContext('AllTasks');                                                            var selectedNode = allTaskModel.getProperty(null,getSelectedContext);                                                                var SvcUrl="+selectedNode.taskId;                                                            var taskDataODataModel = new sap.ui.model.odata.ODataModel(SvcUrl, false);                                                            taskDataODataModel.setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay);                                                               sap.ui.getCore().setModel(taskDataODataModel,"OData");                                                      }

As you can see, the serviceUrl for the oDataModel contains the adress and the attribute "taksId" from the selected listItem. So the passed taskId changes depending on which listItem I click.

What I need to do now, is to bind data from the taskDataODataModel to the simpleForm created in the view. The binding path from the oDataModel has to change, depending on which listItems I click.

The binding should look like this:

simpleForm.bindElement("/InputData('"+taskId+"')", {expand:"Customer"});

Is it possible to use the method bindElement in the controller, and how do I get access to the created controlls from the view?

I tried it with the method this.getView().getContent() but it didn't want to work this way.

I am very thankfull for any help.

Best Regards