Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze the working principle of @ ObjectModel.readOnly in SAP Fiori programming Model Specification

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to parse the working principle of @ ObjectModel.readOnly in the SAP Fiori programming model specification, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

A number of Annotation are defined in the ABAP Programming Model for Fiori help documentation on SAP's official website:

SAP Help Portal

We can master the usage and function of these annotations from their literal meaning and SAP help documentation.

Take @ ObjectModel.readOnly as an example, the CDS view field with this annotation applied is rendered as read-only on the corresponding Fiori UI:

And it cannot be modified programmatically.

When you use these notes, have you ever thought about how they work?

Take @ ObjectModel.readOnly as an example, now follow Jerry to explore its foreground and background implementation.

In the UI5 panel of the Chrome developer tool, find the corresponding property of the control Posting Date, and find that the value of the field editable property is false, which is why it cannot be edited in UI.

If your Chrome developer tool does not have the UI5 tag, please refer to the Jerry article to install the Chrome for UI5 extension:

[Jerry's Fiori original article collection] (Jerry's Fiori original article collection)

Since the background model is CDS view, the foreground UI is obviously based on Fiori Elements. I want to know when the editable property of Posting Date is set to false.

Set a breakpoint in the SmartField.setEditable function, reopen Fiori UI, click Edit to enter the editing model, and the breakpoint is triggered. It can be seen from the call stack that when code calls SmartField.setEditable, the passed parameter is false.

So how is this false calculated? Follow the current call stack to the outer layer and find an important function:

AnnotationHelper.canUpdateProperty.

It can be guessed from the function name that this function is responsible for calculating whether the properties of a control are allowed to be updated (Update), and the context of the work is Annotation.

The semantics of the implementation body of this method is also clear. If the background model field sap:updatable is set to false, the canUpdateProperty function call returns false, causing SmartField.setEditable to render the Fiori UI with the parameter false.

When we open the metadata of the OData service, we find that the sap:updatable corresponding to the posting date field is indeed false.

At this point, the working principle of Fiori UI is analyzed. Let's take a look backstage. I only added @ ObjectModel. ReadOnly to my CDS view, not sap:updatable. Obviously, there is a certain relationship between the two.

In the previous Jerry article, Jerry's CDS view self-study series introduced the CDS view framework processing logic. There is a piece of code:

According to the IF judgment in line 839, if OBJECTMODEL.READONLY is true, the read_only attribute is X.

If the read_only attribute is true, a record with the read_only of X will be added to the table in the attribute collection of the posting date field:

Finally, in the attribute detection logic of the SADL framework, once it is found that there are attributes with read_only X in the table in the field attribute set, lv_creatable and lv_updatable are set to false.

The SADL framework calculates these two Boolean variables with values of false, and finally sets sap:creatable and sap:updatable to false.

The mystery of how the @ ObjectModel.readOnly property works is now unveiled, but it is just the tip of the iceberg of many annotations in the SAP Fiori programming model.

The above is how to analyze the working principle of @ ObjectModel.readOnly in the SAP Fiori programming model specification. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report