VRN
VRN

Reputation: 15

How to bind the odata services to SAPUI5 table?

I've used the below code to bind the odata services to sapui5 table

I was not able to get the data from the oData service to the SAPui5 table, odata is stored in separate vpn client. I'm using reverse proxy server to retrieve the data

Error in the console is shown in the below link output

Code:

//Creating the instance of oData model
var oModel = new sap.ui.model.odata.v2.ODataModel("http://admin-think:88/sap/...",{useBatch : true});
sap.ui.getCore().setModel(oModel,"model1");
console.log(oModel);

// Create instance of table 
var oTable = new sap.ui.table.Table({
    visibleRowCount : 6,
        selectionMode: sap.ui.table.SelectionMode.Single, 
        navigationMode: sap.ui.table.NavigationMode.scrollbar, 
        selectionBehavior: sap.ui.table.SelectionBehavior.RowOnly
    });
  
  // First column "Application"
    oTable.addColumn(new sap.ui.table.Column({
           label : new sap.ui.commons.Label({
                 text : "APPLICATION",
                 textAlign : "Center",

           }),
           template : new sap.ui.commons.TextView({
                textAlign:"Center"}).bindProperty("text","model1>Applno"),              
    }));
 
    // Bind model to table control
    oTable.bindRows("model1>/");

Upvotes: 1

Views: 3253

Answers (1)

jpenninkhof
jpenninkhof

Reputation: 1920

Your service end-point is probably incorrect in this line: var oModel = new sap.ui.model.odata.v2.ODataModel("http://admin- think:88/sap/...",{useBatch : true});.

In the error output you sent, you can see that the application is trying to reach URL http://.../ZTEST1_SRV/CoreOpenAppSet()/$metadata. This results in a 404 status, meaning that that service is not available on that URL. The right URL for the app to download metadata from should probably be http://.../ZTEST1_SRV/$metadata instead.

To solve this, you should remove the CoreOpenAppSet() portion of the variable you're passing to the ODataModel constructor. Instead you should call this 'Function Import' using the callFunction of your ODataModel, i.e.: oModel.callFunction().

When the call of the function import completes and the returned promise is resolved, you can bind the result of the call to your UI using setBindingContext:

var oPromise = oModel.callFunction("/CoreOpenAppSet");
oPromise.contextCreated().then(function(oContext) {
      oView.setBindingContext(oContext);
});

Also, it's a good practice to specify your model and endpoints in the manifest so that they're separated from your code. You can learn more about that here: https://sapui5.netweaver.ondemand.com/docs/guide/8f93bf2b2b13402e9f035128ce8b495f.html

Upvotes: 1

Related Questions