Reputation: 614
I'm trying to compare values in a select input to enable the selection selected="selected"
of some elements.
I`m using: Spring Boot 1.4.0 and Thymeleaf 2.1.5
When I check if there are values I'm sure there are in a list, always returns false
:
<p th:each="modulo : ${usuario.papeis}" th:text="${modulo.nome} + ' - ' + ${meusPapeis} + ' | ' + ${meusPapeis.contains(modulo.nome)}"></p>
Out:
ROLE_DASHBOARD - [ROLE_DASHBOARD, ROLE_USUARIO, ROLE_CONFIGURACOES] | false
Trying another approach:
<p th:each="modulo : ${usuario.papeis}" th:text="${modulo.nome} + ' - ' + ${meusPapeis} + ' | ' + ${#lists.contains(meusPapeis, modulo.nome)}"></p>
Out:
ROLE_DASHBOARD - [ROLE_DASHBOARD, ROLE_USUARIO, ROLE_CONFIGURACOES] | false
Really, I do not know what is the problem, because when I using a literal string the return is true
:
<p th:each="modulo : ${usuario.papeis}" th:text="${modulo.nome} + ' - ' + ${meusPapeis} + ' | ' + ${#lists.contains(meusPapeis, 'ROLE_DASHBOARD')}"></p>
Out:
ROLE_DASHBOARD - [ROLE_DASHBOARD, ROLE_USUARIO, ROLE_CONFIGURACOES] | true
Is there any way to accomplish this kind of comparison, using variable value?
Upvotes: 0
Views: 974
Reputation: 83
You should use the expressions utility #strings
to convert to string with the method toString(stringToConvert)
. Enum is always confusing to use.
Follow the documentation.
try #strings.toString(modulo.nome)
. It should works.
Upvotes: 3