Can the controls of the Smart template be used as ordinary controls?

My colleague asked me this question:

 

As long as you understand the principle of Smart control, you can answer this question.

The answer is: smart control can be defined and used in xml view like normal control, but it must be combined with OData annotation, otherwise it is meaningless. Taking Smart field in Smart control as an example, the detailed principle is introduced in my blog Currency example - how Smart field works .

In summary, this is:

1. The Smart field itself is also a control, more precisely a control without UI output, just a shell. When the UI renders, the smart field will evolve into an input field, drop down list, date picker, or F4 help, all of which need a role to tell the smart field, which is the Odata annotation. The annotation defined in Metadata will determine the final output method of the smart field.

2. Smart control can be used independently from the Smart template framework. That is to say, you can create a very simple xml view, and then use the smart control in this view like a normal control without any problem.

Please refer to this example (the full implementation code is at the end of the article):

 

In the XML view, I define a Smart field and bind it to the Price property.

 

At runtime, it is automatically rendered as a currency field with units. The currency field of EUR in the back is generated like a magic trick, which is actually the effect of the annotation sap:unit="CurrencyCode". As for how the framework parses the annotation and automatically generates the currency field, the relevant code and analysis are in the above-mentioned blog Currency example - how Smart field works .

 

The directory structure of the Fiori application:

 

source code address

To get more original technical articles from Jerry, please follow the public account "Wang Zixi" or scan the QR code below:

 

 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326077663&siteId=291194637