Skip to content
Advertisement

How to use an if-else condition in a SAPUI5 XML-View?

How can I implement an if-else condition in a XML-View in SAPUI5 that uses a flag (condition) from a JSONModel?

So far I have a Controller:

JavaScript

and a View:

JavaScript

Edit:

Is there a better way to do it than by implementing an overkill-feeling XML-Preprocessor?

Advertisement

Answer

OpenUI5 supports Preprocessing Instructions and Expression Binding.

With Preprocessing Instructions you can do stuff like this:

JavaScript

I am not sure if the test in the first line tests for null/not null or true/false. This is where the Expression Binding might be handy: it allows for complex expressions within the curly brackets:

JavaScript

Edit

The following solution might be more simple, but seems a little hacky.

Embed both elements in your XML view, but toggle the visibility with complex expression binding:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement