XML Preprocessor cannot be used in nested XMLView
OpenUI5 version: 1.97.2 Browser/version (+device/version): Chrome Version 98.0.4758.102 Any other tested browsers/devices(OK/FAIL): Fail URL (minimal example if possible): N/A User/password (if required and possible - do not post any confidential information here):
Steps to reproduce the problem:
- Use template:if in a nested XMLView
- See errors:
Uncaught ModuleError: failed to load 'http://schemas/sap/com/sapui5/extension/sap/ui/core/template/1/repeat.js' from
https://sapui5.hana.ondemand.com/1.97.2/resources/http://schemas/sap/com/sapui5/extension/sap/ui/core/template/1/repeat.js:
404
What is the expected result? template:if can be used What happens instead? See errors Any other information? (attach screenshot if possible)
Related files:
main.view.xml:
<mvc:View
xmlns="sap.ui.core"
xmlns:m="sap.m"
xmlns:mvc="sap.ui.core.mvc"
xmlns:template="http://schemas.sap.com/sapui5/extension/sap.ui.core.template/1"
controllerName="controller1"
>
<mvc:XMLView
id="id1"
viewName="view2"
/>
</mvc:View>
view2.view.xml
<mvc:View
xmlns="sap.m"
xmlns:core="sap.ui.core"
xmlns:mvc="sap.ui.core.mvc"
xmlns:template="http://schemas.sap.com/sapui5/extension/sap.ui.core.template/1"
controllerName="cn2"
>
<template:repeat list="{meta>/assList}" var="ass">
<Label text="{path: 'ass>label'}" />
<Text text="{path: 'ass>name'}" />
</template:repeat>
</mvc:View>
controller1.ts
var oModel = new sap.ui.model.json.JSONModel();
var data = {
bands: [
{
name: "Thin Lizzy",
members: [
{ first: "Scott", last: "Gorham", image: "http://www.thinlizzy.org/images/biog_scott.jpg", birthdate: "17. März 1951" },
{ first: "Brian", last: "Robertson", birthdate: "12. Februar 1956" },
{ first: "Brian", last: "Downey", image: "http://www.thinlizzy.org/images/biog_briand.jpg", birthdate: "27. Januar 1951" }
]
}
]
};
oModel.setData(data);
sap.ui.getCore().setModel(oModel);
panelContent = sap.ui.view({
id: this.getView().createId(sSimplePropertiesId),
type: sap.ui.core.mvc.ViewType.XML,
viewName: sPropertiesViewId,
preprocessors: {
xml: { // call default XML pre-processor with arguments
bindingContexts: {
meta: oModel.createBindingContext("/bands/0")
},
models: { meta: oModel }
}
},
});
The template:if cannot be used here in view2.view.xml, but if I move this part of code to main.view.xml it works well. How can I use this preprocessor here?
By the way, I think this is a very common scenario to use template:if like what ngIf does in Angular, do we plan to have a easy way to use this in future?
Hello @taosha121 !
You might want to use a fragment instead of a nested view, see XML Fragments. In that case, XML Templating recursively descends into the fragment as well.
Best regards, Thomas
Thank you for your clarification @ThomasChadzelek Does UI5 have plan to supply a more efficient way to use template in future(like ngIf in angularjs)? Since my project is a big one and there are lots nested XMLView and related controllers we have no resources to refactor them. So I think at this time I cannot use template:if.
Hello @taosha121 ,
Thank you for sharing this finding. I've created an internal incident 2280106147. The status of the issue will be updated here in GitHub.
Regards, Petar
Hello @dimovpetar , Thank you for this information, I cannot wait to try this new feature :)
This item will be tackled in backlog item CPOUI5FRAMEWORK-452. Further updates will be posted here.