SAP / openui5

OpenUI5 lets you build enterprise-ready web applications, responsive to all devices, running on almost any browser of your choice.
http://openui5.org
Apache License 2.0
2.97k stars 1.24k forks source link

XML Preprocessor cannot be used in nested XMLView #3474

Open taosha121 opened 2 years ago

taosha121 commented 2 years ago

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:

  1. Use in a nested XMLView
  2. 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?

can be used What happens instead? See errors Any other information? (attach screenshot if possible) Related files: 1. `main.view.xml`: ``` ``` 2. `view2.view.xml` ``` ``` 3. `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 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 like what ngIf does in Angular, do we plan to have a easy way to use this in future?**
ThomasChadzelek commented 2 years ago

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

taosha121 commented 2 years ago

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 .

dimovpetar commented 2 years ago

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

taosha121 commented 2 years ago

Hello @dimovpetar , Thank you for this information, I cannot wait to try this new feature :)

flovogt commented 10 months ago

This item will be tackled in backlog item CPOUI5FRAMEWORK-452. Further updates will be posted here.