My text have to change color depending on true:false case using Thymeleaf, but whatever I did it doesn't work.
<table th:each="book : ${assignedBooks}">
<tr th:style="${book.getExpired()? 'color: red;' : 'color: blue;'}" th:text="${book.getName() + ', ' + book.getAuthor() + ', ' + book.getYear()}">'someBook'</tr>
</table>
I have checked .getExpired == true, but I don't understand why it still doesn't work.
Your
<table>HTML contains one or more<tr>rows - but those rows do not contain any<td>cells. Place the text (fromth:text="...") inside a<td>.You can troubleshoot problems like this for yourself by looking at the HTML which is produced by Thymeleaf - and which is displayed in your browser. Remember: Thymeleaf generates HTML on the server, and then sends that HTML to the browser. So you can see exactly what Thymeleaf produced (unless it throws an error/exception on the server).
Usually there is a "View Source" menu item in your browser (depending on which browser you are using).
In your case, using the approach in your question, you will probably see something like the following:
See how the lack of any
<td>cells causes the text to be rendered outside of the table. It's up to each browser how it attempts to render incomplete/invalid HTML - so you may see something similar but different.See
tablefor more details on how to create a valid/complete HTML table.