Question

Is it possible to call a method on an object in an "each" loop in Thymeleaf? I'm trying to create a dynamic table where both rows and columns can be dynamic. A Table have a list of Rows and a list of Columns. Column have a method getValue that for a given Row can get the value. But I'm not able to call this getValue(Row row) from Thymeleaf.

I have this Thymeleaf code:

<table>
    <tr th:each="row : ${table.rows}">
          <td th:each="column : ${table.columns}">
               <span th:text="${column.value(row)}"/>
          </td>
    </tr>
</table>

This causes an exception:

Exception evaluating SpringEL expression: "column.value(row)"

Is it even possible to do this in Thymeleaf, e.g. pass variables to methods on other variables?

Était-ce utile?

La solution

I found the problem, since I'm passing in something to this method it's not a getter method so I have to provide the full method name: getValue not just value:

<table>
    <tr th:each="row : ${table.rows}">
        <td th:each="column : ${table.columns}">
            <span th:text="${column.getValue(row)}"/>
        </td>
    </tr>
</table>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top