SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
โคข Open full site

Add Views and Define Routes to Access Them

Add new views to the SAPUI5 web application and declare them in the manifest.

Overview

🎓 beginner 20 min. Sapui5BeginnerHTML5SAP BTP Cloud Foundry EnvironmentSAP Business Application Studio

You will learn

  • โœ”How to add additional views
  • โœ”How to use data binding
  • โœ”How to define routes and targets
  • โœ”How to add additional controller
Nico Schoenteich N Nico Schoenteich December 19, 2022
Created by July 14, 2020
Contributors

Prerequisites

Steps

Step 1 Add two new views
โ€”

In SAPUI5, each view is represented by a dedicated file in the view folder.

  1. Add a new view with a right-click on the view folder and select New File. Name this file List.view.xml.

    newFile
    newFile

  2. The name already suggests that this view will contain a list of products. Add the following file content that defines the views and the list. Note the list already uses data binding to show the product entities as list items.

    XML
    <mvc:View controllerName="sap.btp.sapui5.controller.List" xmlns:mvc="sap.ui.core.mvc" displayBlock="true" xmlns="sap.m">
      <Page id="listPage" title="{i18n>ListTitle}" >
            <List id="list" items="{/Products}">
              <StandardListItem id="_IDGenStandardListItem1" type="Navigation" press="handleListItemPress" title="{ProductName}"/>
            </List>
        </Page>
    </mvc:View>
  3. Repeat step 1 to create another view with the name Detail.view.xml. We will use this view to display details of a given product.

  4. Insert the following content in this new file. In contrast to the list, it uses a relative binding, e.g. the binding path doesn’t start with / like absolute paths do.

    XML
    <mvc:View controllerName="sap.btp.sapui5.controller.Detail" xmlns:mvc="sap.ui.core.mvc" displayBlock="true" xmlns="sap.m">
      <Page id="detail" title="{i18n>DetailTitle}" showNavButton="true" navButtonPress="handleNavButtonPress" >
          <VBox id="_IDGenVBox1">
              <Text id="_IDGenText1" text="{ProductName}" />
              <Text id="_IDGenText2" text="{UnitPrice}" />
              <Text id="_IDGenText3" text="{QuantityPerUnit}" />
              <Text id="_IDGenText4" text="{UnitsInStock}" />
          </VBox>
      </Page>
    </mvc:View>

Hint: You don’t need to rely on the code editor to edit the views. Right-click on any view and select Open With… > Layout Editor to access the WYSIWYG layout editor:

detailView
detailView

Step 2 Add new targets and routes
+
Step 3 Add two new controllers
+
Step 4 Test it
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 4
1. Add two new views 2. Add new targets and routes 3. Add two new controllers 4. Test it

Learn more →