Ian
Ian

Reputation: 466

Thymeleaf th:each noting include din template

I have a Thymeleaf fragment which contains some status text and an th:each which does not appear in the output. I have been able to include the model value in the output its a list<list> and is displayed as [[ 8,9...][..]...]] all the values are correct. I have run with logging.level.org.thymeleaf=trace to get the logs, but it appears that nothing is wrong to me.

The fragment is:

   <span th:fragment="view">
    <div class="centered">
        <h1 th:text="${sudoku_description}"></h1>
        <h1 th:text="${sudoku}"></h1>
        <div class="centered" >
            <th:block th:each="puzzledata, rowStat : ${row}">
                <div class="sudoku-row" >
                    <th:block th:each="row, colStat : ${cell}">
                        <div class="sudoku-cell" row="rowStat.index" col="colStat.index" th:text="${cell}"></div>
                    </th:block>
                </div>
            </th:block>
        </div>
       </div>
    </span>

The 2 tag are present and correct but the following <div class="centered" > on inspection is empty. I have tried changing the th:block to a div made no difference. Running from Intelij no exceptions or errors in the console.

Thymeleaf log extract

[THYMELEAF] View sudoku-view :: view will be handled by ThymeleafViewResolver and a ThymeleafView instance will be created for it
[THYMELEAF][http-nio-8080-exec-1][EXPRESSION_CACHE][CACHE_HIT] Cache hit in cache "EXPRESSION_CACHE" for key "expr|~{sudoku-view :: view}".
[THYMELEAF][http-nio-8080-exec-1] Evaluating fragment: "~{sudoku-view :: view}"
[THYMELEAF][http-nio-8080-exec-1] Evaluating generic token: "sudoku-view"
[THYMELEAF][http-nio-8080-exec-1] Evaluating generic token: "view"
[THYMELEAF][http-nio-8080-exec-1] STARTING PROCESS OF TEMPLATE "sudoku-view::[view]" WITH LOCALE en_GB
[THYMELEAF][http-nio-8080-exec-1][TEMPLATE_CACHE][CACHE_MISS] Cache miss in cache "TEMPLATE_CACHE" for key "sudoku-view::[view]".
[THYMELEAF][http-nio-8080-exec-1] Template resolver match! Resolver "org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver" will resolve template "sudoku-view"
[THYMELEAF][http-nio-8080-exec-1][EXPRESSION_CACHE][CACHE_HIT] Cache hit in cache "EXPRESSION_CACHE" for key "expr|${sudoku_description}".
[THYMELEAF][http-nio-8080-exec-1] Evaluating variable expression: "${sudoku_description}"
[THYMELEAF][http-nio-8080-exec-1] SpringEL expression: evaluating expression "sudoku_description" on target
[THYMELEAF][http-nio-8080-exec-1][EXPRESSION_CACHE][CACHE_HIT] Cache hit in cache "EXPRESSION_CACHE" for key "expr|${sudoku}".
[THYMELEAF][http-nio-8080-exec-1] Evaluating variable expression: "${sudoku}"
[THYMELEAF][http-nio-8080-exec-1] SpringEL expression: evaluating expression "sudoku" on target
[THYMELEAF][http-nio-8080-exec-1][EXPRESSION_CACHE][CACHE_HIT] Cache hit in cache "EXPRESSION_CACHE" for key "each|puzzledata , rowStat : ${row}".
[THYMELEAF][http-nio-8080-exec-1] Evaluating generic token: "puzzledata"
[THYMELEAF][http-nio-8080-exec-1] Evaluating generic token: "rowStat"
[THYMELEAF][http-nio-8080-exec-1] Evaluating variable expression: "${row}"
[THYMELEAF][http-nio-8080-exec-1] SpringEL expression: evaluating expression "row" on target
[THYMELEAF][http-nio-8080-exec-1] FINISHED PROCESS AND OUTPUT OF TEMPLATE "sudoku-view::[view]" WITH LOCALE en_GB
[THYMELEAF][http-nio-8080-exec-1][sudoku-view][en_GB][1127600][1] TEMPLATE "sudoku-view::[view]" WITH LOCALE en_GB PROCESSED IN 1127600 nanoseconds (approx. 1ms)

Upvotes: 0

Views: 60

Answers (1)

Ian
Ian

Reputation: 466

Everyday development day provides evidence of just how stupid one can be.

The problem was the values in the th.each wrong way round!

This works:

<th:block th:each="row, rowStat : ${puzzledata}">

This does not:

 <th:block th:each="puzzledata, rowStat : ${row}">

Upvotes: 1

Related Questions