cancel
Showing results for 
Search instead for 
Did you mean: 

Using OpenUI5 xml views with cdn

Former Member
0 Kudos

This is the error that I get:


GET https://openui5.hana.ondemand.com/resources/ns/views/three-buttons.view.xml 404 (Not Found)

GET https://openui5.hana.ondemand.com/resources/ns/views/three-buttons.view.xml 404 (Not Found)

I am loading the sap-ui-core.js using a cdn. I would like to use xml views located in the viewsfolder and a controller in the controllers folder.

The script tags in the html look like:


<script id="sap-ui-bootstrap"

type="text/javascript"

  src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"

  data-sap-ui-theme="sap_bluecrystal"

  data-sap-ui-libs="sap.ui.commons"

  data-sap-ui-resource-roots="{ ns:'./' }" >

</script> 


<script>

$(function(){

sap.ui.xmlview('ns.views.three-buttons').placeAt('content');

  }); 

</script> 

This is my view:


<mvc:View xmlns="sap.m"

xmlns:mvc="sap.ui.core.mvc"

  controllerName="ns.controllers.three-buttons" >

  <TextView text="Hello World" tooltip="A tooltip for the data"/>

  <Button text="Show Alert" press="btnAlertClick" />

  <Button text="Show Confirm" press="btnConfirmClick" />

  <Button text="Show Message Box" press="btnShowClick" />

</mvc:View>

This is my controller:


sap.ui.controller('three-buttons',{


btnConfirmClick: function btnConfirmClick(){

sap.ui.commons.MessageBox.confirm('Do you want to proceed?',

function(){ new sap.ui.commons.MessageBox.alert('She said yes.'); },'Accept Marraige Proposal');

},


btnConfirmClick: function btnConfirmClick(){


sap.ui.commons.MessageBox.confirm('Do you want to proceed?',

function(){ new sap.ui.commons.MessageBox.alert('She said yes.');

},

'Accept Marraige Proposal');

},


btnShowClick: function btnShowClick() {


var icon = sap.ui.commons.MessageBox.ICON.Warning;

var actions = [sap.ui.commons.MessageBox.Action.YES,sap.ui.commons.MessageBox.Action.NO];

var callback = function(event) {

console.log('The event occurs here',event);

}

new sap.ui.commons.MessageBox.show('Are you sure you want to keep doing this',

icon,

'This could be dangerous',

actions,

callback,

sap.ui.commons.MessageBox.Action.CLOSE);

}

});

Accepted Solutions (0)

Answers (1)

Answers (1)

vijay_kumar49
Active Contributor
0 Kudos

need small clarification when you call the control methods in XML View and .html you used "ns.controllers."

why?

Could you please remove this(ns.controllers.) and try.

Example

sap.ui.controller("local.controller", { // Line 93


same "local.controller" is uses in XML View (controllerName="local.controller") // Line num22

Former Member
0 Kudos

Hi Vijay,

I am trying to use sap.ui.xmlview from the path `./views/three-buttons.view.xml` and the controller from `./controllers/three-buttons.controller.js`, to use them I set up a `resourceroot` called `ns` but I noticed that instead of using the location of the html file as the root directory it seems to be using the location of the `sap-ui-core` as the root directory.

What is the `sapui5` compliant way of loading the view and the controller and wiring them up together and adding them to the page. Does `sap.ui.require` work in this scenario?