cancel
Showing results for 
Search instead for 
Did you mean: 

sap.ui.layout.. simple form....how to bind an odata service to controls inside ?

ashwin_narayan
Participant
0 Kudos

     Hi,

I'm working on SAPui5 ...

Im using a simple form layout and in that form i have input box as well as labels....using an odata service. Now what im looking forward is to try binding the input fields with the odata...

Can anyone advice me on how to do it inside a form??????

Thanks,

Ashwin

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

The way how you bind doesn't differ for the controls inside a simple form. Have a look at the sample code of the simple form in the explored app SAPUI5 Explored .

ashwin_narayan
Participant
0 Kudos

Hi Sakthivel,

Thanks for the response... Will Check the same.

Reagards,

Ashwin

ashwin_narayan
Participant
0 Kudos

Hi Sakthivel,

I guess i need a bit more guidance regarding it....Will Post the code of view and Controller:

View

var oForm = new sap.ui.layout.form.SimpleForm("formid",

  {

  minWidth : 1024,

              maxContainerCols:1,

              editable: true,

              title:"Trial",

              content:[

                      

                       new sap.m.Label({text :"ID", design : "Bold", textAlign : "Begin"}),

                       new sap.m.Input("id",{

                       width:"200px",

                      }),

                       new sap.m.Label({text : "Name",design : "Bold", textAlign : "Begin"}),

                       new sap.m.Input("name",{

                       width:"200px",

                       }),

                       new sap.m.Label({text : "Description", design : "Bold", textAlign : "Begin"}),

                       new sap.m.Input("description",{

                       width:"200px",

                       }),

                       new sap.m.Label({text:"Price"}),

                       new sap.m.Input("price",{

                       width:"200px",

                       }),

                       new sap.m.Label({text:"Rating"}),

                       new sap.m.Input("rating",{

                       width:"200px",

                       }),

                       new sap.m.Label({text:"ReleaseDate"}),

                       new sap.m.Input("date",{value:"2014-09-12T22:22:22",width:"200px"}),

                       new sap.m.Label({text:""}),

                       new sap.m.Button("save",{text:"Save",width:"120px",icon:"sap-icon://save",

                        press: function(){

                        oController.save();

                        }}),

  

                       ]});

Controller

onInit: function() {

var oModel = sap.ui.model.odata.ODataModel("proxy/http/services.odata.org/V3/OData/OData.svc/");

  oModel.oHeaders ={

  "DataServiceVersion": "3.0",

  "MaxDataServiceVersion":"3.0"

  };

sap.ui.getCore().setModel(oModel, "products");

},

Added this without binding it to the controls. Service is an open odata service....

Please share your valuable comments to wards achieving binding.

Thanks,

Ashwin

kedarT
Active Contributor
0 Kudos

Hi Ashwin,

In your controller in onInit method get the instance of the form and then bind the same to the model

something like this:

oForm = sap.ui.getCore().byId("formid");

oForm.setModel(oModel);

Hope this helps.

ashwin_narayan
Participant
0 Kudos

Hi Kedar,

Good to see you again. I tried with setting the mode to the form in the same way...it didnt work.

Thanks,

kedarT
Active Contributor
0 Kudos

As pointed by use from SAPUI5 Explored

this.getView().bindElement("/EntitySetName/0");

ashwin_narayan
Participant
0 Kudos

Tried that even...I dont know if i did it in the write way..Probably i need a piece of code to look into. That would be a great help...

Thanks.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Ashwin,

In controller

onInit: function() {

  this.oModel = sap.ui.model.odata.ODataModel("proxy/http/services.odata.org/V3/OData/OData.svc");

   this.oModel.oHeaders ={

   "DataServiceVersion": "3.0",

   "MaxDataServiceVersion":"3.0"

   };

  

  this.getView().setModel(this.oModel);

    this.getView().bindElement("/Products(0)");

    

  

  },

In View try to bind it to the control

new sap.m.Label({text :"ID", design : "Bold", textAlign : "Begin"}),

new sap.m.Input("id",{value : "{ID}",

                        width:"200px",

                       }),

regards

Indrajith

ashwin_narayan
Participant
0 Kudos

Hi Indra,

Thanks for your response.This is exactly how i did.

Worked!!

Regards,

Ashwin