Step 10: Descriptor for Applications

介绍

All application-specific configuration settings will now further be put in a separate descriptor file called manifest.json. This clearly separates the application coding from the configuration settings and makes our app even more flexible. For example, all SAP Fiori applications are realized as components and come with a descriptor file in order to be hosted in the SAP Fiori launchpad.

1.练习效果

Step 10: Descriptor for Applications - 第1张  | 优通SAP

2.源码

You can view and download all files at Walkthrough – Step 10.

3.Note

In this tutorial, we only introduce the most important settings and parameters of the descriptor file. In SAP Web IDE, you may get validation errors because some settings are missing – you can ignore those in this context.

The content of the manifest.json file is a configuration object in JSON format that contains all global application settings and
parameters. The manifest file is called the descriptor for applications, components, and libraries and is also referred to as “descriptor” or
“app descriptor” when used for applications. It is stored in the webapp folder and read by SAPUI5 to instantiate the component. There are three important sections defined by
namespaces in the manifest.json file:

  • sap.app

    The sap.app namespace contains the following application-specific attributes:

    • id (mandatory): The namespace of our application component

      The ID must not exceed 70 characters. It must be unique and must correspond to the component ID/namespace.

    • type: Defines what we want to configure, here: an application

    • i18n: Defines the path to the resource bundle file

    • title: Title of the application in handlebars syntax referenced from the app’s resource bundle

    • description: Short description text what the application does in handlebars syntax referenced from the
      app’s resource bundle

    • applicationVersion: The version of the application to be able to easily update the application later
      on

  • sap.ui

    The sap.ui namespace contributes the following UI-specific attributes:

    • technology: This value specifies the UI technology; in our case we use SAPUI5

    • deviceTypes: Tells what devices are supported by the app: desktop, tablet, phone (all true by
      default)

  • sap.ui5

    The sap.ui5 namespace adds SAPUI5-specific
    configuration parameters that are automatically processed by SAPUI5.
    The most important parameters are:

    • rootView: If you specify this parameter, the component will automatically instantiate the view and use
      it as the root for this component

    • dependencies: Here we declare the UI libraries used in the application

    • models: In this section of the descriptor we can define models that will be automatically instantiated
      by SAPUI5 when the app starts. Here we can now define the
      local resource bundle. We define the name of the model “i18n” as key and specify the bundle file by namespace. As in the
      previous steps, the file with our translated texts is stored in the i18n folder and named
      i18n.properties. We simply prefix the path to the file with the namespace of our app. The manual
      instantiation in the app component’s init method will be removed later in this step.

    For compatibility reasons the root object and each of the sections state the descriptor version number 1.1.0
    under the internal property _version. Features might be added or changed in future versions of the descriptor and
    the version number helps to identify the application settings by tools that read the descriptor.

3.Note

Properties of the resource bundle are enclosed in two curly brackets in the descriptor. This is not a SAPUI5 data binding syntax, but a variable reference to the resource bundle in the descriptor in handlebars syntax. The referred texts are not visible in the app built in this tutorial but can be read by an application container like the SAP Fiori launchpad.

5.webappindex.html

Now
we declare our component in the body of our index.html. In the bootstrapping script of our index.html,
we enable the ComponentSupport module and remove the sap.m library. Then, we declare our component in
the body via a div tag. This will instantiate the component when the onInit event is executed.

We will
no longer need our index.js from now on, because the descriptor takes care of everything.

6.webapp/i18n/i18n.properties

In the resource bundle we simply add the texts for the app and add comments to
separate the bundle texts semantically.

7.webapp/Component.js

In the component’s metadata section, we now replace the
rootView property with the property key
manifest and the value json. This defines a
reference to the descriptor that will be loaded and parsed automatically when the
component is instantiated. We can now completely remove the lines of code containing
the model instantiation for our resource bundle. It is done automatically by SAPUI5 with the help of
the configuration entries in the descriptor. We can also remove the dependency to
sap/ui/model/resource/ResourceModel and the corresponding
formal parameter ResourceModel because we will not use this inside
our anonymous callback function.

8.Tip

In previous versions of SAPUI5, additional configuration settings for the app, like the service configuration, the root view, and the routing configuration, had to be added to the metadata section of the Component.js file. As of SAPUI5 version 1.30, we recommend that you define these settings in the manifest.json descriptor file. Apps and examples that were created based on an older SAPUI5 version still use the Component.js file for this purpose – so it is still supported, but not recommended.

9. Conventions

  • The descriptor file is named manifest.json and located in
    the webapp folder.

  • Use translatable strings for the title and the description of the app.

留下一个回复

你的email不会被公开。

20 + 1 =