Handling Integers As Strings In Thymeleaf Arrays And Lists
Why do the following Thymeleaf th:if tests fail for the strings '0', '1', and '9'? I have a Java array as follows: String[] arrayData = {'x', '-1', '0', '1', '9', '10', '11'}; The
Solution 1:
I suspect that if you aren't using Spring
, Thymeleaf expressions are being interpreted using OGNL
insteald of SPeL
-- which appears to treat single character constants as type char
instead of type String
and so the #arrays.contains
expressions fail to match.
I don't have a setup to test OGNL, but according to this post, this should work:
<divth:text="${#arrays.contains(arrayData, "0")}" />
(Or maybe #arrays.contains(arrayData, '' + '0')
would work?)
Post a Comment for "Handling Integers As Strings In Thymeleaf Arrays And Lists"