cancel
Showing results for 
Search instead for 
Did you mean: 

How to dynamically bind data to a Controll

Former Member
0 Kudos

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= http://domain.de:50000/bpmodata/taskdata.svc/"+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

Dominik

Accepted Solutions (1)

Accepted Solutions (1)

former_member91307
Contributor
0 Kudos

Hi Dominik,

1) bindContext method could be used to set context dynamically

2) sap.ui.getCore().byId('<id of control>')  could be used to get reference of the content created in view

Below example contains these changes

http://jsbin.com/uxokuc/133/edit

Thanks and Regards, Venkatesh

Answers (2)

Answers (2)

Former Member
0 Kudos

Hey, thanks to both of you. I fixed the issue by using the method bindElement.

sap.ui.getCore().byId('InputForm').bindElement("OData>/InputData('"+selectedNode.taskId+"')",{expand:"RK_Data_Type"});

Best Regards

Dominik

former_member293602
Active Participant
0 Kudos

Hi Dominik,

here: http://scn.sap.com/message/14281224#14281224 you can find another "list - detail" example that shows how to make use of Venkateshs suggestions.

Regards, Frank