Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
175
rated 0 times [  179] [ 4]  / answers: 1 / hits: 23700  / 6 Years ago, tue, july 3, 2018, 12:00:00

Very new to ThymeLeaf, but have encountered a problem on a project I am working on. Getting the following error in the logs:



Exception evaluating SpringEL expression: !searchResults.results.empty


Looking at the offending code it is:



<th:block th:if=${!searchResults.results.empty}>


I assume that the placement of the exclamation mark (!) is incorrect. I have tried:



<th:block th:if=${not searchResults.results.empty}>


But same error evaluating. Can someone help me as to how to negate a check?


More From » thymeleaf

 Answers
36

Assuming from the code you've pasted, you want to implement a check where Thymeleaf checks for empty value in an Object. For that :---



<div th:if= ${searchResults.results != null}>


OR



 <div th:if= ${searchResults.results != ''}>


Also,
Alternatively What you can do is-- check on your Controller itself whether the object is empty or doesn't have any Value and send the response on your html page and then check as per that response on Thymeleaf, Like this :- - -



1.) Your controller :--



    List ls = //some data from you DAO
if(ls.isEmpty()){
model.addAttribute(response, NoData);
}else{
model.addAttribute(response, ls);
}


Then on your Thymeleaf :- - -



<th:block th:if=${response=='NoData'}> No Data Found </th:block>

[#54069] Friday, June 29, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
janettejordynm

Total Points: 550
Total Questions: 94
Total Answers: 98

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
janettejordynm questions
Tue, Nov 24, 20, 00:00, 4 Years ago
Sat, May 23, 20, 00:00, 4 Years ago
Mon, Apr 6, 20, 00:00, 4 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
;