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

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

  2. 2

    HTTPヘッダー 'SOAPAction'の値はサーバーによって認識されませんでした

  3. 3

    STSでループプロセス「クラスパス通知の送信」のループを停止する方法

  4. 4

    レスポンシブウェブサイトの一番下にスティッキーなナビゲーションバーを作成するのに問題がある

  5. 5

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

  6. 6

    Ansibleで複数行のシェルスクリプトを実行する方法

  7. 7

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

  8. 8

    tkinterウィンドウを閉じてもPythonプログラムが終了しない

  9. 9

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

  10. 10

    Rパッケージ「AppliedPredictiveModeling」のインストール中にエラーが発生しました

  11. 11

    テキストフィールドの値に基づいて UIslider を移動します

  12. 12

    Crashlytics:コンパイラー生成とはどういう意味ですか?

  13. 13

    「埋め込みブラウザのOAuthログイン」を有効にしてコールバックURLを指定した後でも、Facebookのコールバックエラーが発生する

  14. 14

    tf.nn_conv2dとtf.nn.depthwise_conv2dの違い

  15. 15

    CSSはアニメーションで変換および回転します

  16. 16

    BLOBストレージからデータを読み取り、Azure関数アプリを使用してデータにアクセスする方法

  17. 17

    Chromeウェブアプリのウェブビューの高さの問題

  18. 18

    Postmanを使用してファイル付きの(ネストされた)jsonオブジェクトを送信する

  19. 19

    amCharts 4で積み上げ棒グラフの輪郭を描く方法は?

  20. 20

    Officeアドインを使用してOutlookの連絡先のリストにプログラムでアクセスすることは可能ですか?

  21. 21

    Reactでclsxを使用する方法

ホットタグ

アーカイブ