0

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.

Luís Soares
  • 5,726
  • 4
  • 39
  • 66
  • 1
    Try changing `votes-positive` to something which does not use a hyphen. That is interpreted as a minus sign inside an OGNL subtraction expression. There's a dupe for this somewhere on SO - I can't find it at the moment... – andrewJames Sep 15 '21 at 23:23
  • 1
    it was that! thank you – Luís Soares Sep 16 '21 at 19:01
  • 1
    Glad it was that. I was not able to find a dupe, so I added an answer, in case it helps future visitors. – andrewJames Sep 16 '21 at 19:21

1 Answers1

0

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

andrewJames
  • 19,570
  • 8
  • 19
  • 51