Issue
i'm trying to check if my list called listPersons is empty or not, but when i check i got an error like this:
Caused by: org.attoparser.ParseException: Exception evaluating SpringEL expression: .... Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "#lists.isEmpty(listPersons" (template: "index" - line 15, col 8)
I have tried this:
<h2 th:if="${#lists.isEmpty(listPersons)}">No hay personas</h2>
<div th:if="${#!lists.isEmpty(listPersons)}">
and this:
${listPersons.isEmpty()}
But none of the options are working. I'm using thymeleaf-3.0.15 and springboot version 2.7.2
In my Java method i have this line:
model.addAttribute("listPersons", personaService.getAll());
Solution
You are not using the conditional statements correctly
, hence you are getting the SPEL error
<div th:if="${#!lists.isEmpty(listPersons)}">
Use the below for your condition
<div th:if="${not #lists.isEmpty(listPersons)}">
Refer https://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#conditional-evaluation
to get more insights.
Answered By - Rishal
Answer Checked By - Clifford M. (JavaFixing Volunteer)