What is Smart Field in SAP UI5

SmartField controls interpret metadata representing entity-relationship models, data types, service capabilities, and annotations in OData services to automatically generate 底层内部控件and reduce the amount of code required to develop applications. In some cases, OData entities are derived from the control's binding context. Properties of OData entities that are changed or displayed with the control are derived from the control's value property.

Important: SmartField, like all SAPUI5 smart controls, retrieves and analyzes metadata and annotations from OData services. OData metadata is its main API. These OData services are not part of the SAPUI5 framework and are usually maintained by the application's back-end developers.

SmartField can evolve and gain new functionality over time. This means that its behavior or functionality may change if the annotation defining this change remains in the backend metadata. To benefit from the new functionality, SAP UI5 applications should be able to adapt to backend metadata. Therefore, SAP recommends using SmartField only when the developer has full control over the application's metadata.

Accessibility

For interoperability and accessibility reasons, SmartField controls must be marked by a sap.ui.comp.smartfield.SmartLabel control instead of a sap.m.Label control, because the sap.m.Label control does not know the internal structure of a SmartField control . If the SmartField control is rendered in a smart container control (such as a SmartForm control), the SmartLabel control is automatically generated to reduce the amount of code required on the application side. However, in other cases, when a SmartField is used alone or outside of a smart container control, such as a SimpleForm control, a SmartLabel control is not automatically generated in these cases. Although sap.ui.comp.smartfield.SmartLabel is a private/internal control, the application allows the following basic uses for labeling SmartField controls.

one example:

<sap.ui.comp.smartfield.SmartLabel labelFor="IDProduct"/>
<sap.ui.comp.smartfield.SmartField id="IDProduct" value="{ProductId}"/>

Using the SmartLabel control alone is not recommended. Only basic usage is allowed, excluding automatic handling of visibility. If used alone, application logic must take care of label visibility.

FieldControl

Defines whether the field is mandatory, hidden, or in read-only/editable mode.

Entity Data Model (EDM) properties can be dynamically annotated using the com.sap.vocabularies.Common.v1.FieldControl annotation in OData V4 models or the sap:field-control annotation in OData V2 models by providing a binding to another property The EDM property of the given path type Edm.Byte, its value in the data model can be:

  • 0: Indicates that the field is hidden. Note: Hidden is an N/A synonym and is deprecated, don't use it to statically hide fields on the UI, use the static FieldControl annotation instead.

  • 1: Indicates that the field is in read-only mode and its value cannot be changed. Note: To statically annotate an EDM property as read-only, use the Org.OData.Core.V1.Computed annotation instead.

  • 3: Indicates that the field is editable and optional (default).

  • 7: Indicates that the field is mandatory from a business perspective. This value does not imply any restriction on the value range of the EDM attribute. For example, to limit the use of a range of values, the standard type facet Nullable with value false must be used to exclude null values, or a term from the Org.OData.Validation.V1 vocabulary must be used.

Guess you like

Origin blog.csdn.net/i042416/article/details/123728870