Search code examples
javahtmlthymeleaf

How to set object id as div id in thymeleaf?


I'm trying to set my object id as div id but when I try running my app I'm getting an error saying

org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing

Another error from the stacktrace:

org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'id' cannot be found on object of type 'io.getstream.core.models.EnrichedActivity' - maybe not public or not valid?

Here's my html code:

<div typeIdFieldName="id" th:id="${#strings.trim(object['id'])}" class="c-default-item" th:each="object : ${objects}"></div>

Solution

  • The problem was that io.getstream.core.models.EnrichedActivity has a getID() getter method name which when accessed using th:id="${object.id}" will throw a exception

    org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'id' cannot be found on object of type 'io.getstream.core.models.EnrichedActivity' - maybe not public or not valid?.
    

    In order to avoid this error, I used the getter method (th:id="${object.getID()}") instead of accessing the property directly.