0

I am trying to create a sapui5 table from xml view but it doesn't seem to be working when I run it from visual studio but when I run it in jsfiddle it runs just fine. What is the reason for this?

Here is the code in my xmlTest.hml:

<!DOCTYPE html>
<html>
<head>
    <script src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" id="sap-ui-bootstrap" data-sap-ui-theme="sap_bluecrystal" data-sap-ui-libs="sap.ui.commons,sap.ui.table"></script>
    <meta charset="utf-8">
    <title>JS Bin</title>
</head>

<body class="sapUiBody" id="content">

    <script id="view1" type="ui5/xmlview">
        <core:view xmlns:core="sap.ui.core"
                   xmlns="sap.ui.commons"
                   xmlns:table="sap.ui.table"
                   xmlns:html="http://www.w3.org/1999/xhtml"
                   controllername="view.Main">
            <table:table width="100%" visiblerowcount="5" selectionmode="Single" editable="false" rows="{/data}">
                <table:title><label text="XML View"></label></table:title>
                <table:column>
                    <label text="Row Num" />
                    <table:template><textfield value="{rowNum}"></textfield></table:template>
                </table:column>
                <table:column>
                    <label text="ID" />
                    <table:template><textfield value="{id}"></textfield></table:template>
                </table:column>
                <table:column>
                    <label text="First Name" />
                    <table:template><textfield value="{name}"></textfield></table:template>
                </table:column>
                <table:column>
                    <label text="Email Address" />
                    <table:template><textfield value="{email}"></textfield></table:template>
                </table:column>

            </table:table>
        </core:view>
    </script>
    <script type="text/javascript">
        var aData = [
        { rowNum: 1, id: 42, name: "Anthony", email: "anthony@example.com" },
        { rowNum: 1, id: 42, name: "Anthony", email: "anthony@example.com" },
        { rowNum: 1, id: 42, name: "Anthony", email: "anthony@example.com" },
        ];
        sap.ui.controller("view.Main", {
            doSomething: function (oEvent) { }
        });

        var oView = sap.ui.xmlview({
            viewContent: jQuery("#view1").html()
        });
        var oModel = new sap.ui.model.json.JSONModel({
            data: aData
        });
        oView.setModel(oModel);
        oView.placeAt("content");
    </script>
</body>
</html>

Running this code from visual studio I get the following errors:

enter image description here

These errors refer to this file.

When I copy my code into jsfiddle it works just fine. Here is my jsfiddle.

FWDekker
  • 689
  • 1
  • 13
  • 23
Anthony
  • 1,399
  • 1
  • 18
  • 35
  • 2
    Can you pull those links up in a browser that you are getting 404's from? – jackncoke Jul 20 '15 at 19:18
  • 1
    a setting within your visual studios software or backend is 90% likely what's going on – Fred Randall Jul 20 '15 at 19:22
  • Its not loading the JavaScript file... you need to make sure the path is correct. – M H Jul 20 '15 at 19:28
  • You have 2 issues in your project. first you are getting a `404 Not found ` error, second you are facing **Access-Control-Allow-Origin** issue. to solve the 1st, open the link in browser to see if the file exists, for second see this [link](http://stackoverflow.com/questions/10636611/how-does-access-control-allow-origin-header-work) and [this](http://stackoverflow.com/questions/12465404/xmlhttprequest-cross-site-domain-issue) – Ramin Omrani Jul 20 '15 at 19:31
  • 1
    @Hanoncs Sure, the problem is the 404 Not Found. But the file is requested by the `sap-ui-core.js` from [OpenUI5](https://openui5.hana.ondemand.com/#docs/guide/99ac68a5b1c3416ab5c84c99fefa250d.html), which OP is trying to use. – FWDekker Jul 20 '15 at 19:31
  • @YourConscious I don't think it has to do with visual studio. I tried running it from notepad++ and I get the same errors. – Anthony Jul 20 '15 at 19:51
  • Try running the html from outside an IDE—I have no issues, nor do I even see a request for https://openui5.hana.ondemand.com/resources/sap/ui/table/table.js. For the sap.ui.table dependency it calls https://openui5.hana.ondemand.com/resources/sap/ui/table/library-preload.json, which returns the script content in json. – Ryan Neuffer Jul 20 '15 at 20:26

1 Answers1

1

The issue is you used lowercase <table:table> instead of <table:Table>

The class name is Table, not table, and as such the file cannot be found (it's Table.js, not table.js)

In your JSFiddle you used the correct casing

Qualiture
  • 4,860
  • 6
  • 26
  • 37