Improving the User Experience

Objectives

After completing this lesson, you will be able to:
  • Arrange fields in the app.
  • Provide input help.

UI Adjustment

In this section, you will learn how to control field properties in the behavior definition and how to adjust the UI in the metadata extension.

Arranging Fields in the UI

Making Fields Read-only

Once you have made the fields read-only, you can see that it makes sense to rearrange them. You do this by annotating the corresponding fields of the projection. Most commonly, you do this in a metadata extension.

Metadata extensions are standalone repository objects that contain the annotations belonging to a particular CDS entity. The idea behind them is to make it easier to understand both the definition of the CDS entity and the annotations by separating them. Otherwise, the CDS definition would become very long and difficult to read.

If you want to use a metadata extension in conjunction with a CDS view, the CDS view must contain the annotation @Metadata.allowExtensions: true. The generator takes care of this for you and automatically generates both a metadata extension for the projection view and the corresponding annotation in the projection view itself.

There are two important UI annotations that you might need to change in the metadata extension. The first is @UI.LineItem. This is an array in which you set the attribute position. This determines the position of the column in the report list page of the app.

The second annotation is @UI.identification. This is, again, an array in which you also set the attribute position. This determines the position of the field in the single object page. that is displayed during the create or update operation.

Rearranging the Fields

How to Control Field Properties

Input Help

In this section, we will learn about providing value help to the users. Watch this video to learn more.

Adjust the User Interface

In this exercise, you will explore the value help provided in the application. In addition, you will adjust the user interface of the generated app: either directly by editing the UI metadata, or indirectly by adjusting the business object behavior.

Template:

  • none

Solution:

  • /LRN/S4D400_C_FLIGHT (Behavior Projection)
  • /LRN/S4D400_C_FLIGHT (Metadata Extension)

Prerequisites

You completed the previous exercises. You created and filled the database table Z##FLIGHT (where ## is your group number) and generated the development objects for an OData UI service.

Task 1: Analyze the Value Help

Verify that a value help is offered for the Currency field on the Object Page. Examine where and how this value help is defined.

Steps

  1. Launch the preview of the OData UI service.

    1. Proceed as you have done in previous exercises.

  2. Open the Object Page for a flight in edit mode.

    1. Proceed as you have done in previous exercises.

  3. Verify that a value help is available for the Currency field.

    1. Open the value help for the Currency field displayed for the flight price.

  4. Return to the development environment and explore the definition of the value help.

Task 2: Adjust the Behavior

Exclude the standard operations create and delete, and set the PlaneTypeID field to read-only .

Note

These changes should only apply to your OData UI service. The business object itself should still support the creation and deletion of flights, and the changing of the airplane type.

Steps

  1. In the behavior projection for your service, disable the standard operations create and delete.

    1. Open the behavior projection ZC_##FLIGHT (where ## is your group number).

    2. Add comment markers in front of the statements use create; and use delete;.

      To add the comment markers, proceed as usual: select the code rows you want to comment and press Ctrl + <.

      Your code should then look like this:

      Code Snippet
      123
      // use create; use update; // use delete;

  2. In the behavior projection of your business object, set the PlaneTypeID field to read-only.

    1. In the behavior projection, add the following code:

      Code Snippet
      1
      field ( readonly ) PlaneTypeID;

      Note

      The precise position of the statement is not important. We suggest that you place it before the use... statements.
  3. Activate the behavior projection.

    1. Press Ctrl + F3 to activate the behavior projection.

Task 3: Adjust the UI Metadata

Hide the administrative fields from the UI. Make sure only CarrierID and ConnectionID are displayed as selection fields on the report list page. Change the field sequence on the Object Page so that PlaneTypeID is displayed before Price.

Steps

  1. Edit the metadata extension of the projection view ZC_##Flight. Remove all UI annotations for the fields LocalCreatedBy, LocalCreatedAt, LocalLastChangedBy, LocalLastChangedAt, and LastChangedAt and replace them with @UI.hidden: true.

    1. Open the metadata extension ZC_##FLIGHT, where ## is your group number.

    2. Adjust the code as follows:

      Code Snippet
      1234567891011121314
      @UI.hidden: true LocalCreatedBy; @UI.hidden: true LocalCreatedAt; @UI.hidden: true LocalLastChangedBy; @UI.hidden: true LocalLastChangedAt; @UI.hidden: true LastChangedAt;
  2. Remove the @UI.selectionField annotation for all elements except for the elements CarrierID and ConnectionID.

    1. Adjust the code as follows:

      Code Snippet
      1234567891011121314151617181920212223
      @UI.identification: [ { position: 30 } ] @UI.lineItem: [ { position: 30 } ] FlightDate; @UI.identification: [ { position: 40 } ] @UI.lineItem: [ { position: 40 } ] Price; @UI.identification: [ { position: 50 } ] @UI.lineItem: [ { position: 50 } ] PlaneTypeID;
  3. Change the position of the PlaneTypeID field on the Object Page. Place it between FlightDate and Price.

    Hint

    The position on the Object Page is specified with annotation @UI.identification.
    1. Change the value of annotation @UI.identification: [ { position: } ] for the PlaneTypeID element. Choose a value that lies between the values for the elements FlightDate and Price.

    2. Adjust the code as follows:

      Code Snippet
      1234567
      @UI.identification: [ { position: 35 } ] @UI.lineItem: [ { position: 50 } ] PlaneTypeID;
  4. Activate the metadata extension.

    1. Press Ctrl + F3 to activate the metadata extension.

Task 4: Verify the Result

Restart the preview of the OData UI service and verify the changes to the user interface.

Steps

  1. Restart the preview of the OData UI service.

    1. Close the browser window or browser tab that contains the preview.

    2. Open the ZUI_##FLIGHT_O4 Service Binding. In the Entity Set and Association list on the right-hand side, first choose the Flight entry and then choose Preview....

  2. On the Report List Page, verify that the buttons Create and Delete have disappeared.

    1. Proceed as you have done in previous exercises.

  3. Make sure that no more administrative fields are displayed on the Report List Page.

    1. Proceed as you have done in previous exercises.

  4. Verify that - apart from the Editing Status field - only two selection fields are visible at the top of the Report List Page. Test their functionality.

    Hint

    Be aware that the selection fields support the entry of multiple values and ranges.
    1. Enter a value in the selection field Airline ID (for example: LH) and choose Go.

    2. Repeat with other values.

  5. For any data set, navigate to the Object Page. Verify that the Delete button has disappeared.

    1. Proceed as you have done in previous exercises.

  6. Make sure that no more administrative fields are displayed on the Object Page.

    1. Proceed as you have done in previous exercises.

  7. Verify that the Plane Type field is displayed after the Flight Date field and before the Flight Price field.

    1. Proceed as you have done in previous exercises.

  8. Switch to edit mode and verify that the value of the Plane Type field cannot be changed.

    1. Proceed as you have done in previous exercises.