UI5 / UI5/openui5

XML Preprocessor cannot be used in nested XMLView

Open
#3,474 5 comments 0 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

enhancement in progress
Dominant language
JavaScript
Stars
3.3k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

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 template:if 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?
template:if can be used
What happens instead?
See errors
Any other information? (attach screenshot if possible)

Related files:

  1. 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>
  1. 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>
  1. 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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.