0

I want to dynamically load a fragment and have the following XML-View:

<mvc:View
    xmlns:html="http://www.w3.org/1999/xhtml"
    xmlns:core="sap.ui.core"
    xmlns:mvc="sap.ui.core.mvc"
    xmlns:l="sap.ui.layout"
    xmlns="sap.m"
    controllerName="controller.App"
    visibleBlock="true">
    <App>
        <pages>
        ...
            <core:Fragment fragmentName="{= ${/BOOL_VALUE} === 'true' ? 'view.fragment1' : 'view.fragment2'}" type="XML" />
        ...
        </pages>
    </App>
</mvc:View>

but somehow, when I load it, the expression inside of fragmentName does not get evaluated and the comparison gets treated like a filename:

Uncaught (in promise) Error: resource {= ${/BOOL_VALUE} === 'true' ? 'view/fragment1' : 'view/fragment2'}.fragment.xml could not be loaded from https://sapui5.hana.ondemand.com/1.44.14/resources/{= ${/BOOL_VALUE} === 'true' ? 'view/fragment1' : 'view/fragment2'}.fragment.xml. Check for 'file not found' or parse errors. Reason: NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'https://sapui5.hana.ondemand.com/1.44.14/resources/%7B=%20$%7B/BOOL_VALUE%7…'true'%20?%20%27view/fragment1%27%20:%20%27view/fragment2%27}.fragment.xml'.
at Object.error (jquery.sap.global-dbg.js:4573)
at p (jquery-dbg.js:3187)
at Object.fireWith [as rejectWith] (jquery-dbg.js:3317)
at h3 (jquery-dbg.js:8787)
at Function.ajax (jquery-dbg.js:8689)
at Object.q.sap.loadResource (jquery.sap.global-dbg.js:4564)
at Object.X.loadTemplate (XMLTemplateProcessor-dbg.js:64)
at constructor.init (Fragment-dbg.js:469)
at constructor.F._initCompositeSupport (Fragment-dbg.js:135)
at ManagedObject-dbg.js:427

What am I doing wrong here?

masrlinu
  • 103
  • 1
  • 14
  • Possible duplicate of [How to dynamically load an XML fragment in XML view?](https://stackoverflow.com/questions/25700383/how-to-dynamically-load-an-xml-fragment-in-xml-view) – Boghyon Hoffmann Sep 25 '18 at 09:10

1 Answers1

0

I do no think you can use expression binding for property 'fragmentName', just like you can't for 'id' or 'class' you should use a formatter function instead.

gaugeinvariante
  • 175
  • 1
  • 10
  • Doesn´t SAP use expression binding for the property 'fragmentName' in [this example](https://sapui5.hana.ondemand.com/sdk/#docs/guide/65da02badf704e03a4fd6bd4c5aba8f4.html)? They use a formatter but do a === 'true' comparison and use the conditional operator ( test ? 'fragment1' : 'fragment2' ). – masrlinu Jul 04 '17 at 11:42
  • Yeah, that example shows how to bind fragmentName to a model porperty or an expression, but it doesn't work! also just binding to a model property like: throws an error. than the log shows clearly that the expression is not calculated but processed as a string – gaugeinvariante Jul 05 '17 at 13:58