Search code examples
springspring-mvcspring-bootthymeleaf

How to set color in td with thymeleaf?


I tried if object.qtdItem == 0, then set the color to red for the TD:

<td th:style="${obj.qtdItem == 0 ? 'color: red;'}" th:text="${obj.text}"></td>

but this happened

error: Caused by:
org.springframework.expression.spel.SpelParseException: Expression
[perfil.qtdItem == 0 ? 'red'] @38: EL1044E: Unexpectedly ran out of
input

Solution

  • The ternary statement needs an else clause e.g.

    <td th:style="${obj.qtdItem == 0 ? 'color: red;' : 'color: some_other_color;'}}" th:text="${obj.text}"></td>