Skip to Content

Hello Folks

Another blog of aggregation binding.

The following example is created in eclipse. To run the sample code in SAP WEBIDE, there will be minor changes. If your basics are clear, then surely, you will spot the change. If you face any challenge while using the sample code in SAP WEBIDE, feel free to comment, and I will help you.

  1. Create a project in Eclipse. My project structure is as shown below:

2. Sample Code in Home.View.xml

<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" controllerName="charts.Home" xmlns:html="http://www.w3.org/1999/xhtml">
<Page title="Products List">
<content>
<List id="idProducts" items="{ProductModel>/results}" noDataText="Loading...">
<StandardListItem title="{ProductModel>ProductName}"/>
</List>
</content>
</Page>
</core:View>

3. Sample Code in Home.controller.js

onInit: function() {
		// local proxy for cross-domain access
		// create OData model from Northwind URL
		var oModel = new sap.ui.model.odata.ODataModel("proxy/http/services.odata.org/Northwind/Northwind.svc", true); 
		oModel.read("/Products", null, null, true, fSuccess, fError);
		//If data is successfully read
		function fSuccess(productdata){
			var oProducts = new sap.ui.model.json.JSONModel();
			sap.ui.getCore().setModel(oProducts,"ProductModel");
			oProducts.setData(productdata);
		};
		//If fails to read data
		function fError(oEvent){
		 console.log("Error occured while reading Product Data!")
		};
		
		
	},

 

Note : If you are getting error “XMLHttpRequest cannot load http://services.odata.org/Northwind/Northwind.svc/$metadata. Invalid HTTP status code 501”  then use url as proxy/http/services……………else, http://services……… will work.

 

Please revert for any query.

 

Thanks!!!

 

Regards

Kiran Israni

 

 

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Zaigham Zaidi

    Hi Kiran,

    Could you please provide any link to learn the basics, samples step by step… for covering all topics i’m a newbie in sap ui5.

    Thanks

     

    (0) 

Leave a Reply