cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 - Issue with XML model binding

former_member243729
Participant
0 Kudos

I am trying to print a very simple output.

My model is XML file & my view is XML. Please help me in fixing the issue.

I am getting the layout but not getting the data into view. Seems like I am missing some logic due to which not able to bind the model to XML view.

And also, I want to understand one thing..when I create a SAPUI5 application in WebIDE using template...I get controller, html and view files. But I also get a component.js file which I think doesnt come when a project is created using Eclipse. And also, normally in eclipse project I believe oninit function is available in controller whereas same is not available in project when created through WEBIDE. I see a init function in component.js file when project is created via WEBIDE. Please clarify this point as well. Thanks.

Component.js

sap.ui.define([
	"sap/ui/core/UIComponent",
	"sap/ui/Device",
	"Practise_XMLview/model/models"
], function(UIComponent, Device, models) {
	"use strict";


	return UIComponent.extend("Practise_XMLview.Component", {


		metadata: {
			manifest: "json"
		},


		/**
		 * The component is initialized by UI5 automatically during the startup of the app and calls the init method once.
		 * @public
		 * @override
		 */
		init: function() {
			// call the base component's init function
			UIComponent.prototype.init.apply(this, arguments);
			
			var oModel = new sap.ui.model.xml.XMLModel();
			oModel.loadData("model/school.xml");


//assigning the model to core so that the model is available through out the application life-cycle.
	sap.ui.getCore().setModel(oModel);


			// set the device model
	//this.setModel(models.createDeviceModel(), "device");
		}
	});


});

<br>
<u>view.js file</u>

<mvc:View controllerName="Practise_XMLview.controller.View1" 
			xmlns:html="http://www.w3.org/1999/xhtml" 
			xmlns:mvc="sap.ui.core.mvc"
			xmlns="sap.m"
			xmlns:sap.ui.core="sap.ui.core"
			xmlns:sap.ui.layout="sap.ui.layout">
	<App>
		<pages>
			<Page title="{i18n>title}">
				<content>
			<List	headerText = "School Details"
					items = "{/details}">
						
			<StandardListItem	title = "{class}"
											type = "Active"
											press = "handleItemSelect">
						</StandardListItem>
					</List>
				</content>
			</Page>
		</pages>
	</App>
</mvc:View>


<u>Controller file</u>


sap.ui.define([
	"sap/ui/core/mvc/Controller"
], function(Controller) {
	"use strict";
	
	var oModel = new sap.ui.model.xml.XMLModel();
	oModel.loadData("model/school.xml");


//assigning the model to core so that the model is available through out the application life-cycle.
	sap.ui.getCore().setModel(oModel);


	return Controller.extend("Practise_XMLview.controller.View1", {


	});


});

<br>
<u>Model file</u>

<?xml version="1.0" encoding="UTF-8"?>


<school>
	<details id="det">
		<class>Grade 1</class>
		<teacher>Sameer</teacher>
		<stucount>32</stucount>
	</details>
</school>



Accepted Solutions (0)

Answers (1)

Answers (1)

former_member243729
Participant
0 Kudos

Thanks..the issue has been resolved by making a small correction to model bindingComponent.js file

However I still have this confusion...

what is the difference b/w controller.js & component.js ?

Former Member

Each controller has a corresponding view. It's used for the events of that view. The component is global for the app and is used for startup and some general functionality of the app as a whole. The difference becomes very clear once you have multiple views, each one with its own controller.

former_member243729
Participant
0 Kudos

Perfect. Thanks and now this clear my doubt.

But then I am left with last doubt...

When I create a SAPUI5 project from eclipse I see only view & controller but when I create a project from WEBIDE I see component.js file as well as an additional file. And also, the controller.js file of Eclipse project has oninit method where I can instatiate any object but in the project created via WEBIDE I dont see this method in controller.js rather I see it in component.js (with slightly different method name 'init')...

Is my understanding correct that the project structure and file structure is different when created from Eclipse & WEBIDE..