on ‎2019 Oct 08 3:15 AM
HI,
I'm a SAPUI5 beginner, having a problem with if-else statement in XML view.
I'm trying to create a table in XML view. Values in table are binded from .json file (in the future, values will be binded via oData service). Below is the code.
<mvc:View
controllerName="demo.prototype.controller.TestController"
xmlns:t="sap.ui.table"
xmlns:mvc="sap.ui.core.mvc"
xmlns:u="sap.ui.unified"
xmlns:c="sap.ui.core"
xmlns="sap.m"
xmlns:template="http://schemas.sap.com/sapui5/extension/sap.ui.core.template/1">
<t:Table
rows="{/ProductCollection}"
visibleRowCount="7"
selectionMode="MultiToggle"
width="75rem">
<t:columns>
<t:Column width="10rem">
<Label text="{i18n>modelGroup}" />
<t:template>
<Label text="{modelGroup}" />
</t:template>
</t:Column>
<t:Column width="4rem">
<Label text="{i18n>line}" />
<t:template>
<Label text="{line}"/>
</t:template>
</t:Column>
<t:Column width="6rem">
<Label text="{i18n>date}" />
<t:template>
<Input value="{data1}"
description="/100" />
</t:template>
</t:Column>
</t:columns>
</t:Table>
</mvc:View>
I want to switch Control(Input or Label) or to switch "display description or not" in Input control, depending on flg (true or false) in .json file. But I cannot find the way to do that. I found "http://schemas.sap.com/sapui5/extension/sap.ui.core.template/1" in other questions and tried, but it did not work.
There are 2 ways probably・Implement in Controller ・Implement in XML view.
The 2nd way is preferable for me.
Could anyone help me?
If there is missing information, please point them out.
Thank you for your support.
Request clarification before answering.
Hi,
I think you are looking for preprocessing concept in XML View -
Have a look on - https://sapui5.hana.ondemand.com/#/topic/fc185952184c48618ef46306a1517f8c
With Preprocessing Instructions you can do stuff like this:
<template:iftest="{marketed}">
<template:then>
<Labeltext="product is marketed"/>
</template:then><template:else>
<Imagesrc="path.jpg"/>
</template:else>
</template:if>If you are looking for simple solution (Not Recommended/Suggetsed approach), you can use expression binding, create two columns(Label and Input) then set the visibility as below
<Input visible= "{= ${condition} === true ? <option1> : <option2>}">
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for your comment. I checked URL and tried, but it does not work.
Do you know whether xmlns:template="http://schemas.sap.com/sapui5/extension/sap.ui.core.template/1" is correct or not?
According to message, error is caused by Error: failed to load 'http://schemas/sap/com/sapui5/extension/sap/ui/core/template/1/if.js'
I was looking for alternate but cannot found.
Sorry to bother you again.
you cannot use view with template directly. you have to pre-process the template.
use the easy way : a flag to control the visibility
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 8 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.