Search code examples
thymeleaf

numbers.sequence in thymeleaf with thymeleaf variable


This works :

<tr>
   <td th:text="${Blade__${iBladeIndex}__CutterMultiImagesCount}"></td>
</tr>

Returns the correct number in <td>

But this :

<tr th:each="i: ${#numbers.sequence(0, ${Blade__${iBladeIndex}__CutterMultiImagesCount} - 1)}">
    <td th:text="${i}"></td>
</tr>

returns an error :

org.springframework.expression.spel.SpelParseException: Expression [#numbers.sequence(0, ${Blade0CutterMultiImagesCount} - 1)] @22: EL1043E: Unexpected token. Expected 'rparen())' but was 'lcurly({)'

It's wrapped around <th:block th:with="iBladeIndex=|${iterstat.index}|">


Solution

  • It should probably be:

    <tr th:each="i: ${#numbers.sequence(0, Blade__${iBladeIndex}__CutterMultiImagesCount - 1)}">
    

    (I would recommend not using preprocessing in most cases though.)