$(function () { pageContext.i18n.modTalk = 'moderation talk'; pageContext.i18n.replyToComment = 'Reply'; pageContext.i18n.modTalkEmpty = 'moderation talk is empty'; pageContext.url.getModTalk = "/comments/%25ID%25/listModTalk.json"; pageContext.url.possibleCommentRecipients = "/comments/%ID%/possibleRecipients.json"; pageContext.url.commentEdit = '/comments/%25ID%25/edit.html'; pageContext.url.commentView = '/comments/%ID%/view.html'; pageContext.i18n.commentVisibility = { 'full': 'Viewable by all users', 'op': 'Viewable by the original poster', 'mod': 'Viewable by moderators', 'opAndMod': 'Viewable by moderators and the original poster', 'other': 'Advanced visibility', 'dialogTitle': 'Comment visibility', 'selectGroups': 'Visible to groups', 'selectOther': 'Other recipients', 'selectOriginalPoster': 'Original poster', 'selectModerators': 'Moderators', 'selectAssignees': 'Asked to answer users' }; pageContext.i18n.commentMenuLabels = { 'comment-edit': 'comments.menu.edit', 'comment-delete': 'comments.menu.delete', 'comment-convert': 'comments.menu.convert' };pageContext.i18n.answer= { bestAnswer: 'Best Answer', controlBar : { accept: 'Accept', unaccept: 'Unaccept', acceptCommand: 'Accept this answer as correct', cancelAcceptedCommand: 'Remove this answers accepted status' } }; window.croles = { u: false, op: false, m: false, og: false, as: false, ag: false, dc: false, doc: false, eo: false, ea: false }; tools.init({ q: { e: false, ew: false, eo: false, r: false, ro: false, d: false, dow: false, fv: false, c: false, co: false, p: false, tm: false , ms: false, mos: false }, n: { f: false, vf: false, vfo: false, vr: false, vro: false, c: false, co: false, vu: false, vd: false, w: false, wo: false, l: false }, c: { e: false, eo: false, d: false, dow: false, ta: false, tao: false, l: false }, a: { e: false, ew: false, eo: false, d: false, dow: false, a: false, aoq: false, ao: false, tc: false, tco: false, p: false, tm: false }, pc: croles }, { tc: true, nsc: true }); commandUtils.initializeLabels(); }); Skip to Content
avatar image
Former Member

Error in oData Model example

Hi Team,

I am trying to build a quick example for oData Model implementation by building a Table and fetching data from url "http://services.odata.org/V2/oData/oData.svc/". When I am running it , My table is getting displayed but data is not fetched.

Below i my code for Model, View and Controller.

Request you to rectify my mistake.

index.html

<!DOCTYPE HTML>

<html> <head>

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>

<script src="resources/sap-ui-core.js"

id="sap-ui-bootstrap"

data-sap-ui-libs="sap.ui.commons,sap.ui.table,sap.ui.model"

data-sap-ui-theme="sap_bluecrystal">

</script>

<script>

sap.ui.localResources("button");

var view = sap.ui.view({id:"idView11", viewName:"button.View1", type:sap.ui.core.mvc.ViewType.JS});

view.placeAt("content");

</script>

</head> <body role="application"> <div id="content"></div> </body> </html>

view

sap.ui.jsview("button.View1", { /** Specifies the Controller belonging to this View. * In the case that it is not implemented, or that "null" is returned, this View does not have a Controller. * @memberOf button.View1 */ getControllerName : function() { return "button.View1"; }, /** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed. * Since the Controller is given to this method, its event handlers can be attached right away. * @memberOf button.View1 */ createContent : function(oController) { //Create table var oTable = new sap.ui.table.Table("TAB1", { title : "Table using oData", visibleRowCount : 5, navigationMode : sap.ui.table.NavigationMode.Paginator }

);

var oColumn1 = new sap.ui.table.Column("C1",{ label : "ID", template : new sap.ui.commons.TextField().bindProperty("value","ID"), });

oTable.addColumn(oColumn1);

var oColumn2 = new sap.ui.table.Column("C2",{ label : "Name", template : new sap.ui.commons.TextField().bindProperty("value","Name"), });

oTable.addColumn(oColumn2);

return oTable;

} });

Controller:

onInit: function() {

//Create an oData Model

var oModel = new sap.ui.model.odata.ODataModel("proxy/http/services.odata.org/V2/oData/oData.svc/");

//Bind the table

var oTable = sap.ui.getCore().byId("TAB1");

//set model to the table oTable.setModel(oModel); oTable.bindRows("/Products"); },

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Nov 10, 2016 at 01:11 PM

    Can u pls. try with below code

    sap.ui.jsview("firstproject.FirstApp", {

    getControllerName : function() {
    return "firstproject.FirstApp";
    },

    createContent : function(oController) {

    var oTable = new sap.ui.table.Table();

    oTable.addColumn(new sap.ui.table.Column({label: new sap.ui.commons.Label({text: "ID"}),template: new sap.ui.commons.TextView().bindProperty("text","ID")}));
    oTable.addColumn(new sap.ui.table.Column({label: new sap.ui.commons.Label({text: "Name"}),template: new sap.ui.commons.TextView().bindProperty("text","Name")}));

    var oModel1 = new sap.ui.model.odata.ODataModel("http://services.odata.org/V2/OData/OData.svc/");
    oTable.setModel(oModel1);
    oTable.bindRows("/Products");
    oTable.placeAt("content");
    }

    });

    Hope this should be use full !!!

    Regards

    Vijay

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Vijay,

      I tried with the same code but I am not getting anything in output(blank page)

      createContent : function(oController) {
      
      
      		//Create table
      		var oTable = new sap.ui.table.Table();
      
      
      		oTable.addColumn(new sap.ui.table.Column({
      			label: new sap.ui.commons.Label({text: "ID"}),
      			template: new sap.ui.commons.TextView().bindProperty("text","ID")
      			}));
      		oTable.addColumn(new sap.ui.table.Column({
      			label: new sap.ui.commons.Label({text: "Name"}),
      			template: new sap.ui.commons.TextView().bindProperty("text","Name")
      			}));
      
      
      		var oModel1 = new sap.ui.model.odata.ODataModel("http://services.odata.org/V2/OData/OData.svc/");
      		oTable.setModel(oModel1);
      		oTable.bindRows("/Products");
      		
      		
      		
      		return oTable;
      
      Please check where I am doing wrong
      
      Regards,
      Sindhu
  • Mar 09, 2017 at 03:49 PM

    your folder structure?

    Add comment
    10|10000 characters needed characters exceeded