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 Smart Controls to the User Interface

Replace the current UI controls with more complex (smart) controls that fully leverage the OData protocol.

Overview

🎓 intermediate 25 min. SAP FioriIntermediateOdataSapui5SAP Build Work Zone Standard EditionUser InterfaceHTML5CloudFree Tier

You will learn

  • βœ”How to use smart controls like the SmartFilterBar, SmartList, or the ObjectPage.
  • βœ”Why smart controls can save you much boilerplate code.
Nico Schoenteich N Nico Schoenteich July 19, 2024
Created by March 23, 2020
Contributors

Prerequisites

Prerequisites

Steps

Step 1 Enrich the products page with smart controls
β€”

Smart controls are a specific category of SAPUI5 controls that have some special super powers - the most prominent being the tight integration with the OData protocol version 2. Smart controls read the metadata of bound OData services, which allows them to easily provide features such as filtering, value help, and many more. Read more about smart controls in the documentation.

Smart controls only work with OData V2. For OData V4, the SAP Fiori Elements Flexible Programming Model provides “building blocks” with similar functionality.

Also, the “freestyle” approach shown in this tutorial is only recommended for use cases that require a lot of custom implementation. If your application fits one of the available SAP Fiori elements floorplans, you should think about using SAP Fiori elements rather than a freestyle approach. The application built as part of this tutorial should probably also be using SAP Fiori elements, for the purpose of education however, a freestyle approach is shown.

Replace the content of the myui5app/webapp/view/Products.view.xml file with the following code, which imports various smart control libraries and makes use of the smartFilterBar and smartList:

XML
<mvc:View controllerName="myui5app.controller.Products" displayBlock="true"
    xmlns="sap.m"
    xmlns:smartFilterBar="sap.ui.comp.smartfilterbar"
    xmlns:smartList="sap.ui.comp.smartlist"
    xmlns:smartTable="sap.ui.comp.smarttable"
    xmlns:mvc="sap.ui.core.mvc">
    <Page id="Products">
        <smartFilterBar:SmartFilterBar id="smartFilterBar" persistencyKey="UniqueAndStablePersistencyKey" entitySet="Products" considerSelectionVariants="true" />
        <smartList:SmartList id="smartProductList" smartFilter="smartFilterBar" entitySet="Products" expandFields="Category" header="Products List" showRowCount="true" showFullScreenButton="true" enableAutoBinding="true">
            <smartList:listItemTemplate>
                <StandardListItem id="listTemplate" type="Navigation" press="handleListItemPress" title="{ProductName}" info="{= ${UnitPrice} + ' €' }" description="{Category/CategoryName}" />
            </smartList:listItemTemplate>
        </smartList:SmartList>
    </Page>
</mvc:View>

Your page should now display product names and contain a smart header with fully functional filter capabilities (give it a first test run if you like).

smartlist
smartlist

Did you notice that the list items display the category names, even though the selected entity set Products doesn’t contain these values. It does that because the property expandFields="Category" was defined, which expands the CategoryID to a full, nested entity. There is nothing you need to do apart from defining the field names to expand. All magic happens behind the scenes in the OData protocol. Feel free to remove this property from the view to see how the displayed data changes.

Step 2 Use the smart filter bar
+
Step 3 Navigate to the detail view
+
Step 4 Use an ObjectPage in the detail view
+
Step 5 Enrich the detail view controller
+
Step 6 Add more content to the ObjectPage
+
Step 7 Populate the empty fields
+

Resources

Discussion

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

Submit detailed feedback Discuss in Community
Steps
Step 1 of 7
1. Enrich the products page with smart controls 2. Use the smart filter bar 3. Navigate to the detail view 4. Use an ObjectPage in the detail view 5. Enrich the detail view controller 6. Add more content to the ObjectPage 7. Populate the empty fields

Learn more →