View replacement lets you completely substitute an existing view in a standard application with your own custom implementation. This powerful extension mechanism gives you full control over the UI structure and behavior when other customization approaches aren’t sufficient.
View replacement should be your choice in the following cases:
Remember:
Before opting for view replacement, consider whether Extension Points or View Modification could achieve your goals. View replacement completely overrides the original view, which means you’ll need to maintain compatibility with any future updates to the standard application.
Here’s an example of a basic view replacement:
Original view named SampleView.view.xml in the standard application:
<mvc:View xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc">
<Text text="SAP View 'SampleView' - this should be replaced by the customer View"></Text>
</mvc:View>
Your custom replacement view, named CustomView.view.xml:
Note:
You can still reference the original controller or, if needed, provide a completely new one. For more information, see the recommendations below.
<mvc:View xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" controller="samples.components.ext.sap.SampleView">
<VBox class="sapUiMediumMargin">
<Text text="Custom View 'Sub1' - this replaces the original SAP View 'SampleView'"></Text>
<Button text="Custom Action" press="onCustomAction"/>
<Panel headerText="Additional Content">
<Text text="This content was not available in the original view"/>
</Panel>
</VBox>
</mvc:View>
To activate the view replacement, configure it in your component’s manifest.json file
{
"sap.ui5": {
"extends": {
"extensions": {
"sap.ui.viewReplacements": {
"samples.components.ext.sap.SampleView": {
"viewName": "samples.components.ext.customer.CustomView",
"type": "XML"
}
}
}
}
}
}
The view replacement configuration follows this structure:
sap.ui.viewReplacements: This subsection of sap.ui5/extensions identifies this as a view replacement.
samples.components.ext.sap.SampleView: The fully qualified name of the view you want to replace.
viewName: The fully qualified name of your custom replacement view.
type: The view type.
When implementing view replacements, follow these recommendations: