Question

How can I use null check inside a list in Thymeleaf. I have the following

<tr th:each="idBean : ${idBeanLst}">

                <td th:text="${idBean.identifierId}"></td>
                <td th:text="${idBean.idNumber}"></td>
                <td th:text="${idBean.issueLocation}"></td>
                <td th:text="${idBean.issueDate}"></td>
                <td th:text="${idBean.expiryDate}"></td>

idBeanLst is the list that contains identifierBean.Now I want to show the result only if idBean.idNumber !=null.How to put this check?

Was it helpful?

Solution

You can add an if statement at the end tr tag

<tr th:each="idBean : ${idBeanLst}" th:if="${idBean.idNumber != null}">
            <td th:text="${idBean.identifierId}"></td>
            <td th:text="${idBean.idNumber}"></td>
            <td th:text="${idBean.issueLocation}"></td>
            <td th:text="${idBean.issueDate}"></td>
            <td th:text="${idBean.expiryDate}"></td>
</tr>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top