将 UI 元数据添加到数据模型

ABAP RESTful 应用程序编程模型 › 开发 › 开发应用程序 › 开发非托管事务应用 › 提供含业务对象结构的 CDS 数据模型 › 在 CDS 投影视图中投影数据模型 › 将 UI 元数据添加到数据模型

使用 @UI 注释定义 Fiori UI 的布局。

要使业务服务可供任何 UI 客户端使用,UI 相关元数据将添加到后端服务。这些元数据使用 @UI 注释进行维护,这些注释将添加到整个实体,或者与特定 UI 元素相关(如果与特定 UI 元素相关)添加到相应的 CDS 元素。由于这些注释可能变得过多,因此建议在元数据扩展中维护 UI 注释。

元数据扩展用于定义相应数据定义之外的 CDS 视图的 CDS 注释。使用元数据扩展可以通过将数据模型与域特定的语义(例如 UI 使用的 UI 相关信息)分开来分离关注点。CDS 元数据扩展始终分配到特定层,例如核心、行业、合作伙伴或客户。这些行业可以扩展数据模型的元数据。

为映射视图创建元数据扩展

对于 Travel UI 服务,为作为业务对象构成层次结构一部分的 CDS 映射视图创建元数据扩展。它们是:

 

根层

第一个子层

业务对象结构的 CDS 视图

/DMO/I_TRAVEL_U

/DMO/I_BOOKING_U

业务对象映射的 CDS 视图

/DMO/C_TRAVEL_U

/DMO/C_BOOKING_U

UI 注释的元数据扩展

/DMO/C_TRAVEL_U

/DMO/C_BOOKING_U

备注

根据元数据扩展的命名规则:开发对象的命名规则,元数据扩展的名称与其相关 CDS 实体的名称相同。

要创建元数据扩展对象,请在相关 CDS 实体的项目浏览器中打开上下文菜单,然后选择新建元数据扩展。按照向导中的步骤获取标注相关映射视图的元数据扩展模板。

语法:

@Metadata.layer: layer
annotate view CDSProjectionView
    with
{
    element_name;

}

为元数据扩展定义元数据层,并插入要注释的元素。元数据扩展的分层允许对每个开发层进行堆叠,以 #CORE 开头。然后,每个层都可以向服务添加自己的层特定元数据。

要使用投影视图的元数据扩展,请在投影视图的实体级别添加注释 @Metadata.allowExtensions:true。

对元数据扩展中的 CDS 元素进行注释

必须在元素列表中插入要在元数据扩展中注释的任何 CDS 元素。

CDS 映射视图的元数据扩展 /DMO/C_Travel_U

以下列表(列表 1)为您提供具有相同名称的映射视图的元数据扩展 /DMO/C_Travel_U 的实施。它标注投影视图本身及其元素。

要指定 Fiori UI 的抬头文本,请在实体级别使用注释 @UI.headerInfo。它指定列表标题以及对象页面的标题。UI 的主要构件块指定为 UI 构面。注释 @UI.facet 还支持导航到子实体,该子实体在对象页面的页面正文中表示为列表。

元素级别的注释用于定义元素在列表报表和对象页面上的位置。此外,还指定元素对于列表报表的重要性。如果元素标记为低重要性,则不会在具有窄屏幕的设备上显示。还会在需要 UI 中过滤器栏的元素上定义选择字段。

对于操作,您可以在 Fiori 元素 UI 上定义操作按钮。此场景包含将差旅状态设置为已预订的操作。要在列表报表页面上公开操作,操作按钮的信息将添加到元素上的 @UI.lineItem 注释。

用于在 UI 上公开操作按钮的语法:

  @UI: { lineItem: { type: #FOR_ACTION, dataAction: 'action_name', label: 'Button Label' } ] }
  element;

展开以下代码示例以查看元数据扩展 /DMO/_C_Travel_U 的源代码。

示例代码

@Metadata.layer: #CORE

@UI: { headerInfo: { typeName: 'Travel',
                     typeNamePlural: 'Travels',
                     title: { type: #STANDARD,
                              value: 'TravelID' } } }

annotate view /DMO/C_Travel_U with

{
  @UI.facet: [ { id:            'Travel',
                 purpose:       #STANDARD,
                 type:          #IDENTIFICATION_REFERENCE,
                 label:         'Travel',
                 position:      10 },
               { id:            'Booking',
                 purpose:       #STANDARD,
                 type:          #LINEITEM_REFERENCE,
                 label:         'Booking',
                 position:      20,
                 targetElement: '_Booking'}]

  @UI: { lineItem:       [ { position: 10,
                             importance: #HIGH } ],
         identification: [ { position: 10 } ],
         selectionField: [ { position: 10 } ] }
  TravelID;

  @UI: { lineItem:       [ { position: 20,
                             importance: #HIGH } ],
         identification: [ { position: 20 } ],
         selectionField: [ { position: 20 } ] }
  AgencyID;

  @UI: { lineItem:       [ { position: 30,
                             importance: #HIGH } ],
         identification: [ { position: 30 } ],
         selectionField: [ { position: 30 } ] }
  CustomerID;

  @UI: { lineItem:       [ { position: 40,
                              importance: #MEDIUM } ],
         identification: [ { position: 40 } ] }
  BeginDate;

  @UI: { lineItem:       [ { position: 41,
                             importance: #MEDIUM } ],
         identification: [ { position: 41 } ] }
  EndDate;

  @UI: { identification: [ { position: 42 } ] }
  BookingFee;

  @UI: { identification: [ { position: 43 } ] }
  TotalPrice;

  @UI: { identification:[ { position: 45,
                            label: 'Comment' } ] }
  Memo;

  @UI: { lineItem:      [ { position: 50,
                            importance: #HIGH },
                          { type: #FOR_ACTION,
                            dataAction: 'set_status_booked',
                            label: 'Set to Booked' } ],
         identification: [ { position: 46, label: 'Travel Status' } ],
         selectionField: [{ position: 40 }],
         textArrangement:   #TEXT_ONLY }
  Status;

  @UI.hidden: true
  StatusText;
}

CDS 映射视图的元数据扩展 /DMO/C_Booking_U

以下列表(列表 2)为您提供具有相同名称的映射视图的元数据扩展 /DMO/C_Booking_U 的实施。它标注投影视图本身及其元素。

要指定 Fiori UI 的抬头文本,请在实体级别使用注释 @UI.headerInfo。它指定列表标题以及对象页面的标题。UI 的主要构件块指定为 UI 构面。

元素级别的注释用于定义元素在列表报表和对象页面上的位置。此外,还指定元素对于列表报表的重要性。还会在需要 UI 中过滤器栏的元素上定义选择字段。

展开以下代码示例以查看元数据扩展 /DMO/C_Booking_U 的源代码。

示例代码

@Metadata.layer: #CORE

@UI: {
  headerInfo: { typeName: 'Booking',
                typeNamePlural: 'Bookings',
                title: { type: #STANDARD,
                         value: 'BookingID' } } }

annotate view /DMO/C_Booking_U with
{
  @UI.facet: [ { id:            'Booking',
                 purpose:       #STANDARD,
                 type:          #IDENTIFICATION_REFERENCE,
                 label:         'Booking',
                 position:      10 } ]

  @UI: { lineItem:       [ { position: 20,
                             importance: #HIGH } ],
         identification: [ { position: 20 } ] }
  BookingID;

  @UI: { lineItem:       [ { position: 30,
                             importance: #HIGH } ],
         identification: [ { position: 30 } ] }
  BookingDate;

  @UI: { lineItem:       [ { position: 40,
                             importance: #HIGH } ],
         identification: [ { position: 40 } ] }
  CustomerID;

  @UI: { lineItem:       [ { position: 50,
                             importance: #HIGH } ],
         identification: [ { position: 50 } ] }

  AirlineID;

  @UI: { lineItem:       [ { position: 60,
                             importance: #HIGH } ],
         identification: [ { position: 60 } ] }
  ConnectionID;

  @UI: { lineItem:       [ { position: 70,
                             importance: #HIGH } ],
         identification: [ { position: 70 } ] }

  FlightDate;
  @UI: { lineItem:       [ { position: 80,
                             importance: #HIGH } ],
                             identification: [ { position: 80 } ] }
  FlightPrice;
}