0

Spring Boot application with Thymeleaf views gives me parsing error when I try to use index variable inside array like this:

<tr th:each="cdItem, stat : *{commonDataItems}">      
      <td th:text=${stat.index}>Index</td>      
      <td> <input type="text" th:field=*{commonDataItems[__${stat.index}__].value>Value</td>    
</tr>

This <td th:text=${stat.index}>Index</td> line is for testing purposes and it gives the right index value, but next line <td> <input type="text" th:field=*{commonDataItems[__${stat.index}__].value>Value</td> gives parsing error. Error message is:

org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "*{commonDataItems[__${stat.index}__].value" (common)
    at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:238) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.thymeleaf.standard.expression.StandardExpressionParser.parseExpression(StandardExpressionParser.java:79) ~[thymeleaf-2.1.4.RELEASE.jar:2.1.4.RELEASE]

Any ideas what is wrong?

3
  • 1
    Are you missing quotes or is that just a typo: th:field="*{commonDataItems[__${stat.index}__].value" Commented Apr 12, 2016 at 8:59
  • Thanks, that was it. Not too proud of myself now though :) You can write that as an answer and I'll accept it. Commented Apr 12, 2016 at 10:41
  • 1
    Ta, you just needed some fresh eyes :-) Commented Apr 12, 2016 at 10:49

1 Answer 1

2

Missing quotes! th:field="*{commonDataItems[__${stat.index}__].value"

So:

<tr th:each="cdItem, stat : *{commonDataItems}">      
      <td th:text=${stat.index}>Index</td>      
      <td> <input type="text" th:field="*{commonDataItems[__${stat.index}__].value">Value</td>    
</tr>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.