Reputation: 920
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
window.temp = function() {return 'test'};
and to execute it via <Text text="{:=temp()}" />
=> fail<Input value="{:=(new Date()).getFullYear()}" />
breaks parser and is in jsfiddle therefor outcommented.
The Error Message is Expected ) but instead saw Date at position 9 - {:=(new Date()).getFullYear()} sap.ui.base.ExpressionParserFirst 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
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
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