monavari-lebrecht
monavari-lebrecht

Reputation: 920

Function Call in Expression Binding in OpenUI5/SAPUI5

Problem is to print out the current year by using expression binding that was introduced with 1.28.

Expression Binding is capable of executing global accessible JS Functions.

Goal: Execute (new Date()).getFullYear() in expression binding

First question is: Why does the parser break? Is it a bug or am I doing something wrong?

Second question is: Even if the goal is not possible. Why is my second attempt also not working?

Upvotes: 3

Views: 2058

Answers (2)

Justin Sane
Justin Sane

Reputation: 66

Had a similar problem. As commenters have stated, function calls from global symbols are allowed, so an obvious hack would be:

On init:

Date.evilhack = (a => new Date(a));

And in the expression binding:

{= Date.evilhack(${something}).getFullYear() }

If anyone has a better idea, please share! I know there are custom formatters, but I'm looking for a minimal, hopefully clean, solution.

Upvotes: 0

matbtt
matbtt

Reputation: 4231

I assume that the parser breaks as it does not support the new operator. Your second example is not working as only functions which are available via global symbols can be used. The window object is not listed there.

Upvotes: 1

Related Questions