Page Is Blank Without Throwing Any Errors

I am trying to display few tiles in a tile container which fetches data from a dummy JSON file. I have coded exactly shown in this sample. But my page appears empty. Also it doesn't show any errors in the console. Below are the snippets of my code.

View1.controller.js

sap.ui.define([
  "sap/ui/core/mvc/Controller"
], function(Controller) {
  "use strict";

  return Controller.extend("AdminMovie.controller.View1", {

  });
});

View1.view.xml

<mvc:View
  displayBlock="true" 
  controllerName="AdminMovie.controller.View1"
  xmlns:mvc="sap.ui.core.mvc"
  xmlns="sap.m"
>
  <Page showHeader="false" enableScrolling="false">
    <mvc:XMLView viewName="AdminMovie.view.TileContainer"/>
    <footer>
      <OverflowToolbar id="otbFooter">
        <ToolbarSpacer/>
        <Button type="Accept" text="Add New Movie"/>
      </OverflowToolbar>
    </footer>
  </Page>
</mvc:View>

TileContailner.view.xml

<mvc:View
  xmlns:core="sap.ui.core"
  xmlns:mvc="sap.ui.core.mvc"
  xmlns="sap.m"
  controllerName="AdminMovie.controller.TileContainer"
>
  <App>
    <pages>
      <Page
        showHeader="false"
        enableScrolling="false"
        title="Stark"
      >
        <TileContainer id="container"
          tileDelete="handleTileDelete"
          tiles="{/MovieCollection}"
        >
          <HBox>
            <StandardTile
              icon="{icon}"
              type="{type}"
              number="{number}"
              numberUnit="{numberUnit}"
              title="{title}"
              info="{info}"
              infoState="{infoState}"
            />
          </HBox>
        </TileContainer>
        <OverflowToolbar>
          <Toolbar>
            <ToolbarSpacer/>
            <Button
              text="Edit"
              press=".handleEditPress"
            />
            <ToolbarSpacer/>
          </Toolbar>
        </OverflowToolbar>
      </Page>
    </pages>
  </App>
</mvc:View>

TileContainer.js

sap.ui.define([
  "jquery.sap.global",
  "sap/ui/core/mvc/Controller",
  "sap/ui/model/json/JSONModel"
], function(jQuery, Controller, JSONModel) {
  "use strict";

  return Controller.extend("AdminMovie.controller.TileContainer", {
    onInit: function(evt) {
      // set mock model
      var sPath = jQuery.sap.getModulePath("AdminMovie", "/MovieCollection.json");
      var oModel = new JSONModel(sPath);
      this.getView().setModel(oModel);
    },

    handleEditPress: function(evt) {
      var oTileContainer = this.byId("container");
      var newValue = !oTileContainer.getEditable();
      oTileContainer.setEditable(newValue);
      evt.getSource().setText(newValue ? "Done" : "Edit");
    },

    handleTileDelete: function(evt) {
      var tile = evt.getParameter("tile");
      evt.getSource().removeTile(tile);
    }

  });
});

Solution 1:

Your root view is missing a root control such as sap.m.AppAPI which:

  • Writes a bunch of properties into the header of HTML document, e.g. the viewport meta tag,
  • Writes height: 100% to all its parent elements.[src]

Without a root control, the content will be displayed improperly. Hence, adding an <App> should be sufficient in your case:

<!-- root view -->
<mvc:View
  xmlns:mvc="sap.ui.core.mvc"
  xmlns="sap.m"
  height="100%"
  displayBlock="true"
  controllerName="..."
>
  <App id="myApp"> <!-- Not in other views! -->
    <!-- content -->
  </App>
</mvc:View>

The reason why the linked sample is working, is that the control sap.m.App was already added in index.html. The samples shown in the Demo Kit, however, often miss index.html in the code page to be shown which can be confusing.


Alternatively, without sap.m.App, you could also add the following in index.html and in the root view:

  1. Add 100% height to <html>, and to <div data-sap-ui-component> if it exists.

    <html style="height: 100%;">
     <head>
       <!-- ... -->
       <script id="sap-ui-bootstrap" src="..."
         data-sap-ui-modules="sap/ui/core/ComponentSupport"
         data-...>
       </script>
     </head>
     <body id="content" class="sapUiBody">
       <div style="height: 100%;"
         data-sap-ui-component
         data-height="100%"
         data-...>
       </div>
     </body>
    </html>
  2. And in the root view:
    <mvc:View height="100%" ...>
      <!-- no <App> here -->

Example: https://embed.plnkr.co/6AJKC0

This will make the content visible too but without the need to use sap.m.App in the root view.

Solution 2:

⚠️ For other readers: if you're not using a TileContainer, see my previous answer for general solutions → https://stackoverflow.com/a/50951902/5846045

Causes for empty TileContainer

  1. Unexpected child control
  2. Besides the missing root control, the <TileContainer> in your code contains a list of HBoxes.

    <TileContainer>
      <HBox> <!-- ❌ Wrong aggregation child! -->
        <StandardTile />

    The default aggregation of TileContainer is, however, a control that is derived from sap.m.Tile.

    UI5 TileContainer aggregation

    Hence, you should be getting the following error message in the browser console:

    Uncaught Error: "Element sap.m.HBox#__hbox1" is not valid for aggregation "tiles" of Element sap.m.TileContainer#__xmlview1--container

    Please, remove the <HBox> as the binding template:

    <TileContainer>
      <StandardTile /> <!-- ✔️ -->
    

  3. TileContainer contains only one Tile
  4. There was a bug (issue #1813) in the TileContainer which failed making the aggregation visible in Chrome (works in Firefox) if there was only a single Tile. The fix is delivered with OpenUI5 version 1.56+, 1.54.2+, 1.52.8+, 1.50.9+, 1.48.19+, and 1.46.2+.