Passing an object into a Thymeleaf fragment

miklg

I'm attempting to implement a Thymeleaf fragment containing a form, and having trouble passing in the th:object value.

The fragment:

    <div th:fragment="editCard(colSize, title, formObject, formAction, fields)"  th:class="${'col-lg-' + colSize}">
    <div class="card">
        <div class="card-header d-flex align-items-center">
            <h4 th:text="${title}"></h4>
        </div>
        <div class="card-body">
            <form th:object="${__${formObject}__}" th:action="${formAction}" method="post" class="form-horizontal">
                <div th:replace="${fields}"></div>
            </form>
        </div>
    </div>
</div>

And the invocation:

                <div th:replace="fragments/cards2 :: editCard(colSize='12', title='Concert', formObject=${concert}, formAction='/concert/save', fields=~{ :: .fields})" >
                <div class="fields">
                    <input type="hidden" th:field="*{id}"/>
                    <!--/*/ <th:block th:include="fragments/elements :: editSelect(label='Season', val='x', field='season', selectList='${seasons}', itemText='${item}', autofocus='autofocus')"></th:block> /*/-->
                    <!--/*/ <th:block th:include="fragments/elements :: editText(label='Title', val='x', field='title', autofocus='')"></th:block> /*/-->
                    <!--/*/ <th:block th:include="fragments/elements :: editCheckbox(label='Tour', field='tour')"></th:block> /*/-->

                </div>
            </div>
        </div>

There seems to be an interaction between Thymeleaf and Spring binding that prevents the formObject from being accurately passed. I'm not sure exactly which Thymeleaf syntax combination between caller and fragment is correct.

Metroids

You should pass the string 'concert' instead of the object in this case. It's a bit weird, but it should work for you.

<div th:replace="fragments/cards2 :: editCard(colSize='12', title='Concert', formObject='concert', formAction='/concert/save', fields=~{ :: .fields})" >

and keep the rest the same. What you really want is for the expression th:object="${__${formObject}__}" to evaluate to th:object="${concert}" (which passing a string will do). Right now it's evaluating to something weird like th:object="${java.class.whatever@123412}" (the default toString for ${concert}).

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

TOP 一覧

  1. 1

    モーダルダイアログを自動的に閉じる-サーバーコードが完了したら、Googleスプレッドシートのダイアログを閉じます

  2. 2

    セレンのモデルダイアログからテキストを抽出するにはどうすればよいですか?

  3. 3

    CSSのみを使用して三角形のアニメーションを作成する方法

  4. 4

    ドロップダウンリストで選択したアイテムのQComboBoxスタイル

  5. 5

    ZScalerと証明書の問題により、Dockerを使用できません

  6. 6

    PyCharmリモートインタープリターはプロジェクトタブにサイトパッケージのコンテンツを表示しません

  7. 7

    Windows 10でのUSB入力デバイスの挿入/取り外しの検出

  8. 8

    Excel - count multiple words per cell in a range of cells

  9. 9

    PictureBoxで画像のブレンドを無効にする

  10. 10

    Windows 10 Pro 1709を1803、1809、または1903に更新しますか?

  11. 11

    スタート画面にシャットダウンタイルを追加するにはどうすればよいですか?

  12. 12

    Python / SciPyのピーク検出アルゴリズム

  13. 13

    Luaの文字列から特定の特殊文字を削除するにはどうすればよいですか?

  14. 14

    Pythonを使用して、リストからデータを読み取り、特定の値をElasticsearchにインデックス付けするにはどうすればよいですか?

  15. 15

    LinuxでPySide2(Qt for Python)をインストールするQt Designerはどこにありますか?

  16. 16

    goormIDEは、ターミナルがロードするデフォルトプロジェクトを変更します

  17. 17

    QGISとPostGIS(マップポイント(米国の地図上にraduisを使用した緯度と経度)

  18. 18

    MLでのデータ前処理の背後にある直感

  19. 19

    ターミナルから「入力ソースの変更」ショートカットを設定する

  20. 20

    パンダは異なる名前の列に追加します

  21. 21

    同じクラスの異なるバージョンを使用したクラスローディング:java.lang.LinkageError:名前の重複クラス定義を試行しました

ホットタグ

アーカイブ