Home > Back-end >  Thymeleaf: "Exception evaluating OGNL expression" in a simple for loop
Thymeleaf: "Exception evaluating OGNL expression" in a simple for loop

Time:09-17

I have this controller:

it.render(
   "my-list.html",
   mapOf( 
      "votes-positive" to repo.votesOf("x"),
  )
)

//...
data class Vote(
   val name: String,
   val type: Type,
) {
   enum class Type { POS, NEG }
}

my template file "my-list.html:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<body>
    <div th:each="vote : ${votes-positive}">
        <span th:text="${vote.name}"></span>
    </div>
</body>

I'm getting this error when running it, which is driving me crazy:

[qtp119358627-23] ERROR org.thymeleaf.TemplateEngine - [THYMELEAF][qtp119358627-23] Exception processing template "my-list.html": Exception evaluating OGNL expression: "vote.name" (template: "my-list.html" - line 21, col 15)
org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating OGNL expression: "vote.name" (template: "my-list.html" - line 21, col 15)

Is there a Thymleaf debug mode? Is there a way to print the model tree? I don't know why the expression is wrong.

CodePudding user response:

Try changing votes-positive to something which does not use a hyphen. That is interpreted as a minus sign inside an OGNL subtraction expression.

  • Related