on 10-31-2016 4:42 AM
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>
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 ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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..
User | Count |
---|---|
96 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.