Concatenating strings

Concatenating strings

This post was updated on .

Dear

In the documentation it's written that concatenating strings can be done with the "+"-sign. However, we've found that doesn't work as expected. Well, it does work, but it first converts them to BigDecimals, then throws an error per value that's not a number and then concatenates it as strings.

So: "a" + "b" ==> a to BigDecimal, b to BigDecimal. a is not a number ==> error, b is not a number ==> error. concatenate as strings (so the end result works)

We've noticed that this causes most of the Thymeleaf CPU load and IO actions on our servers.

This is not only for the "+" sign, but also for "eq", "ne", ... "boolean eq true", will first convert to bigdecimals, etc etc etc.

For now we'll have to refactor all our code to using the #strings, #bools, ... expression utilities.

Is this something that'll be fixed in Thymeleaf 3?

Edit: How would one perform the following check: "Object ne null". I can't find an equivalent. For strings, I can just use #strings.isEmpty()

Re: Concatenating strings

I agree that it might be possible to optimize that intent to convert the operands into BigDecimal, but we've never seen this meaning a significant percent of template execution time in our profiling/benchmarking sessions (and we are *really* into profiling and optimizing hot spots in 3.0), so this is a scenario I'd definitely want to have a more careful look at. Maybe your templates are especially heavy on String append operations?

Re: Concatenating strings

The problem is not only with the concatenation. It also occurs with the "eq", "ne", ...as states in my first post. And not just strings, but also with booleans and objects (maybe some other?)
Also, is there an alternative way for th:if="${Object ne null}" ? Is th:if="${Object}" an alternative and how would it be processed? I want to avoid using the EvaluateAsNumber (as #strings.concat does for example)