0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

thymeleaf内で使う演算子について

htmlでthymeleafを使えば変数の指定ができると知り、「htmlに渡したリストのn番目のメッセージ内容を取得する」といった使い方をしていたところの問題が発生。

具体的には20人毎に1ページのスライダーを使用していた時の話で

1ページ目 1~20人目

2ページ目 21~40人目 といったもの。

上記のリストの情報を取得するために「n番目」の指定が必要だったのでnを変数として扱った。

<div th:text="${list.get( ${stat.index} + (20 * ${i}) ).getMSG()" class="message"></div>

上記のような書き方を行った際、whiteLabelエラーが表示された。

${i}の指定が間違っているのはないか?と思い

<div th:text="${list.get( ${stat.index} + (20 * 1) ).getMSG()" class="message"></div>

このように直接数字を書いてみたがエラーは解消されず・・・何故??

いろんな記事を検索してみるも同じような現象に出会えず。
他にも()を増やしたり減らしたり、{}を増やしたり減らしたり、演算子を別のものに変えたり・・・と、途方もなくガチャガチャ弄っていたが一向に改善なし。

力技で動作させてみる方法に切り替えた。

無理くり改善させたコード

<div type="hidden" th:with="msgNum = ${stat.index} + 20 * ${i}">
    <div th:text="${list.get(msgNum)" class="message"></div>
</div>

このように計算を変数に入れてしまえば想定通りの動きになった。

ただ書き方が気に入らない・・・なんかヤダなという思いが消えず・・・

推測として

  • thタグ内で使える変数の数に指定がある?
  • {}内で使える演算子の数に指定がある?

等が原因なのでは?と考えている。

今後原因がわかれば追記なりで詳しく説明していきたいと思う。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?