dvIta
dvIta

Reputation: 137

SAPUI5 xml view error

I'm new at sapui5 mvc i searched everywhere but nothing seem to work for me. I have a simple view and controller and just need a help to start with this. I have to do this with separated files. Here is my code

LinkGroup.view.xml

<mvc:View
  controllerName="sap.m.sample.Link.LinkGroup"
  xmlns:l="sap.ui.layout"
  xmlns:mvc="sap.ui.core.mvc"
  xmlns="sap.m">
  <l:VerticalLayout
    class="marginVerticalContent"
    width="100%">
    <l:content>
      <Link
        text="Click me"
        press="handleLinkPress" />
      <Link
        text="Disabled link"
        enabled="false" />
      <Link
        text="Open SAP Homepage"
        target="_blank"
        href="http://www.sap.com" />
    </l:content>
  </l:VerticalLayout>
</mvc:View>

LinkGroup.controller.js

sap.ui.controller("sap.m.sample.Link.LinkGroup", {

    handleLinkPress: function (evt) {
        jQuery.sap.require("sap.m.MessageBox");
        sap.m.MessageBox.alert("Link was clicked!");
    }

});

index.aspx

<head>
 <script type="text/javascript">

      sap.ui.controller("LinkGroup", { });

      var oView = sap.ui.xmlview({
          viewContent: jQuery('#LinkGroup').html()
      });

      oView.setModel(new sap.ui.model.json.JSONModel({ }));

      oView.placeAt('content');

    </script>
</head>
<body class="sapUiBody">
    <form id="form1" runat="server">
    <div id="content">
    </div>
    </form>
</body>

This throws the "Neither view name/content nor an XML node is given" error. Every help appreciated

Upvotes: 0

Views: 3359

Answers (1)

Qualiture
Qualiture

Reputation: 4920

I believe the error comes from:

var oView = sap.ui.xmlview({
    viewContent: jQuery('#LinkGroup').html()
});

It expects a DOM element with ID LinkGroup which is most likely not available (if your XMLView is part of the index.html file within <script> tag which has an ID LinkGroup, then it would work):

<script id="LinkGroup" type="ui5/xmlview">
    <mvc:View
        controllerName="sap.m.sample.Link.LinkGroup"
        xmlns:l="sap.ui.layout"
        xmlns:mvc="sap.ui.core.mvc"
        xmlns="sap.m">
        <!-- etc -->
    </mvc:View>
</script>

However, if your XMLView is in a separate file, you could simply use this in your index.html:

var view = sap.ui.view({id:"idmain1", viewName:"sap.m.sample.Link.LinkGroup", type:sap.ui.core.mvc.ViewType.XML});
view.placeAt("content");

Upvotes: 2

Related Questions