odata binding


How to connect odata with backend ?
To fetch data in view.xml UI page. first we required to add the odata url in manifest.json file.


How to add url in manifest.json file ?
First add the script in index.html file and access the component.js file after that add the model in component.js file to link the url to manifest.json file. In the manifest.json file put the service url and in the web.xml file put the initial url to link the odata to UI.


Index.html

<script src="resources/sap-ui-core.js"
        id="sap-ui-bootstrap"
        data-sap-ui-libs="sap.m"
        data-sap-ui-theme="sap_bluecrystal"
        data-sap-ui-compatVersion="edge"
        data-sap-ui-xx-bindingSyntax="complex"
        data-sap-ui-preload="async"
        data-sap-ui-resourceroots='{"myapp":"./"}'>
    </script>

      <script>
    sap.ui.getCore().attachInit(function(){
        new sap.m.Shell({
        app:new sap.ui.core.ComponentContainer({
          name:"myapp",
          height:"100%"
        })
        ­­­­­­ }).placeAt("content"); ( we are navigation here to content.js file )
    })
    </script>

Then its links to component.js file after that add the code in component.js file to navigate page to manifest.json file.

component.js

        metadata: {
          manifest: "json" (here we navigate page to manifest.json file)
        },

        init : function() {
          UIComponent.prototype.init.apply(this,arguments);
           var deviceModel = new sap.ui.model.json.JSONModel({
                    isPhone : jQuery.device.is.phone,
                    isNoPhone : !jQuery.device.is.phone,
                    listMode : (jQuery.device.is.phone) ? "SingleSelectMaster" : "SingleSelectMaster",
                    listItemType : (jQuery.device.is.phone) ? "Active" : "Active"
                    });
                    deviceModel.setDefaultBindingMode("OneWay");
                    this.setModel(deviceModel, "device");


        }


Manifest.json file

"models": {
      "ZMM_AUTO_DISPATCH_BILL": {
        "dataSource": "ZPP_DWD_TYT_BILL", (Here we set the serviceurl of odata)
        "settings": {
          "useBatch": false,
          "defaultUpdateMethod":"PUT"
        }
      }
}


Also set the initial link to we.xml file to fetch the full url.


Web.xml
<context-param>
    <param-name>com.sap.ui5.proxy.REMOTE_LOCATION</param-name>
    <param-value>http://mabcdse1.corp.xyz.com:8000/</param-value> (initial url)
  </context-param>






Post a Comment

Previous Post Next Post