loio |
---|
f51dbb78e7d5448e838cdc04bdf65403 |
view on: demo kit nightly build | demo kit latest release
Stable IDs are IDs for controls, elements, or components that you set yourself in the respective id
property or attribute as opposed to IDs that are generated by OpenUI5. Stable means that the IDs are concatenated with the application component ID and do not have any auto-generated parts.
If you don't define IDs, OpenUI5 generates them dynamically. These IDs are not static and might differ from program run to program run. For example, the page and table in the following XML view could have the generated IDs __page0
and __table0
at runtime:
<mvc:View
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc">
<Page>
<content>
<Table>
</Table>
</content>
</Page>
</mvc:View>
The generated IDs change whenever the control structure of the app changes. The sequence of instantiation also plays a role: If there are two views with unstable IDs in the app, depending on the order the views are opened, they get the generated IDs __view0
and __view1
. This is an issue for the following features that require stable IDs:
-
Automated tests
To check the behavior of apps at runtime, these tests find controls by searching for stable IDs. If you use OPA in OpenUI5, you're able to find controls via other criteria like control type, display name and others. For more information, see Integration Testing with One Page Acceptance Tests (OPA5).
-
Inline help tools
These tools display user assistance information directly in the app and depend on stable IDs (example: SAP Companion).
Stable IDs are an important prerequisite for SAPUI5 flexibility services, automated testing, and inline help tools. Apps with stable IDs are of high quality and offer customers more functionality. Therefore, we strongly recommend that you use stable IDs whenever possible (some technical controls don't need stable IDs, such as
CustomData
).
If some controls have disappeared after a software upgrade or the way in which they can be identified has been changed, this has a direct impact on the functions that depend on stable IDs. These stable IDs are part of the public API of the app, and therefore must be kept stable over the life cycle of the app.
Do not delete any control that has a stable ID. If you need to remove a control from an app, set the control's
visible
property tofalse
.
Using the rule Stable control IDs are required for SAPUI5 flexibility services in the Support Assistant, you can check whether all controls use stable IDs. For more information, see How to Check If All Your IDs Are Stable.
Views |
|
Extension points |
If you use extension points, use stable IDs for nested views and prefixes for nested controls of a fragment. |
Controls |
|
Components |
For example, if you instantiate a component inside an HTML page, set the ID of the component as shown below. The reason for this is that components could be displayed more than once on a page. To get unique IDs for the views and controls inside the component, they must be prefixed with the component ID. All views in the component that are created by the framework are automatically prefixed with the component ID. As described above, for the programmatically generated components, you must do it yourself. Example: // "Shell" required from module "sap/m/Shell"
new Shell({
app: new ComponentContainer({
height : "100%",
name : "sap.ui.demo.worklist",
settings: {
id: "worklist"
}
})
}).placeAt("content");
|
Embedded Components |
If you want to add an embedded component with a stable ID, you have two options:
|
XML fragments |
If you use XML fragments in your app, make sure they are instantiated with the correct view ID prefix. To simplify this you can use the Example using the controller function // "this" is the controller instance
this.loadFragment({
// note: no ID prefix needed
name: "my.fragment.SampleFragment"
}); Example using the generic function // "Fragment" required from module "sap/ui/core/Fragment"
// "this" is the controller instance
Fragment.load({
// note: ID prefix needed
id: this.getView().getId(),
name: "my.fragment.SampleFragment"
}); |
Choose names for your stable IDs that describe the semantics of your views and controls, such as page or table.
For the allowed sequence of characters, see the namespace sap.ui.core.ID. But bear in mind not use hyphens (-) as separators in your names as they would interfere with the ones that are added automatically by the framework.
Example:
Let's say you're building an app with a component called myProducts
. You're using stable IDs for the views and contained views. Here's what the concatenated IDs that are generated at runtime look like:
Component |
Views |
Contained Views |
Concatenated IDs |
---|---|---|---|
|
|
|
|
|
|
||
|
|
|
|
|
|
With the Support Assistant, you can analyze whether there are any issues with the stable IDs used in your app. Here's how you can check this:
- Open your app in a browser.
- Enter the shortcut [Ctrl] + [Shift] + [Alt] /[Option] + [P] to start the Support Assistant.
- In the Technical Information Dialog, choose Activate Support Assistant.
- In the table on the left, deselect all rules.
- Click on the Rules column.
- Filter for
stable
and choose Enter. - Select the Stable control IDs are required for SAPUI5 flexibility services rule.
- Choose Analyze.
If any generated IDs are found, set the IDs for these controls manually as described here.
Related Information