views are defined using sap libraries as follows −
- xml with html, mixed, or standalone: library- sap.ui.core.mvc.xmlview
- javascript: library- sap.ui.core.mvc.jsview
- json: library - sap.ui.core.mvc.jsonview
- html: library - sap.ui.core.mvc.htmlview
javascript view sample
sap.ui.jsview(“sap.hcm.address”, {
getcontrollername: function() {
return “sap.hcm.address”;
},
createcontent: function(ocontroller) {
var obutton = new sap.ui.commons.button({ text: “hello” });
obutton.attachpress(function() {
ocontroller.hello();
})
return obutton;
}
});
html view sample
<template data-controller-name = ”sap.hcm.address’>
<h1>title</h1>
<div> embedded html </div>
<div class = ”test” data-sap-ui-type = ”sap.ui.commons.button”
id = ”button1” data-text = ”hello” data-press = ”sayhello”>
</div>
</template>
similarly, you can create json view derived from sap.ui.core.mvc.jsonview.
{
“type”:”sap.ui.core.mvc.jsonview”,
“controllername”:”sap.hcm.address”,
……………………….
…………………...
…………………….
}
comparison of view types
the following table lists key features associated with mvc concept and comparison of different view types w.r.t the features.
| feature | js view | xml view | json view | html view |
|---|---|---|---|---|
| standard and custom libraries | yes | yes | yes | yes |
| properties of types string, int boolean, float | yes | yes | yes | yes |
| aggregation 1:1, 1:n association 1:1, 1:n | yes | yes | yes | yes |
| simple data binding | yes | yes | yes | yes |
| customize data binding | yes | no | no | no |
| embedded html | no | yes | no | no |
| code completion | yes | yes | no | no |
| templating | yes | no | no | no |
| validation | no | yes | no | no |
| single event listener | yes | yes | yes | yes |