Search code examples
thymeleaf

Why the content of my table is still visible when the condition is not set in Thymeleaf?


I want that my table is only visible if the size of the list opleidingen is not null. But altough the list is empty, he still shows the header of the table and the icons. What do I do wrong? Thankyou

<table th:if="${opleidingen.size() != 0}">
    <theader>
        <tr>
            <th>Code</th>
            <th>Titel</th>
            <th>Thema</th>
            <th>Delete</th>
            <th>Pas Aan</th>
        </tr>
    </theader>
    <tbody>
    <tr th:each="opleiding: ${opleidingen}">
        <td><span th:text="${opleiding.getCode()}"/></th>
        <td><span th:text="${opleiding.getTitel()}"/></th>
        <td><span th:text="${opleiding.getThema()}"/></th>
        <td><a href="/admin.html"><img src="../static/Delete.gif"/></a></th>
        <td><a href="/edit.html"><img src="../static/Edit.gif"/></a></th>
        </tr>
    </tbody>

</table>

Keeps being visible: the header of the table theader tekst and the images. Why, since there are no items to be shown, the whole table shouldn't be shown?


Solution

  • You need to have Thymeleaf render the template, otherwise, the Thymeleaf specific attributes will not do anything.