Thymeleaf で Twitter Bootstrap フィールドを処理するための推奨される方法についてアドバイスが必要です。推奨事項はそれほど簡単ではないことを知っているので、それについての私の考えを書きました。コメントをいただければ幸いです。最後に具体的な質問があります。最初に、生成に必要なものを示すフラグメントを試しました
<div th:fragment="textfield">
<div class="control-group"
th:classappend="${#fields.hasErrors('__${fId}__')}? 'error'">
<label class="control-label" th:for="${fId}"
th:text="#{model.__*{class.simpleName}__.__${fId}__}+':'">
FirstName
</label>
<div class="controls">
<input type="text" th:class="${inputclass}" th:field="*{__${fId}__}" th:disabled="${disabled}"/>
<span class="help-inline" th:if="${#fields.hasErrors('__${fId}__')}"
th:errors="*{__${fId}__}"></span>
</div>
</div>
</div>
で使用できる
<div class="control-group replace" th:include="templates::textfield" th:with="fId='userId'" th:remove="tag">
<label class="control-label replace">Benutzer-Id</label>
<div class="controls replace">
<input type="text" value=""/>
</div>
</div>
または要するに
<div class="control-group replace" th:include="templates::textfield" th:with="fId='userId'" th:remove="tag"/>
入力についてはあまり柔軟ではないため、チェックボックスには独自のフラグメントが必要です。
次に、レイアウト アプローチを選択します。
<div layout:fragment="bsfield">
<div class="control-group" th:classappend="${#fields.hasErrors('__${fId}__')}? 'error'">
<label class="control-label" th:for="${fId}"
th:text="#{model.__*{class.simpleName}__.__${fId}__}+':'">
FirstName </label>
<div class="controls">
<span layout:fragment="bsinput" th:remove="tag">
<input type="text" class="replace" th:field="*{__${fId}__}" th:disabled="${disabled}"/>
</span>
<span class="help-inline" th:if="${#fields.hasErrors('__${fId}__')}"
th:errors="*{__${fId}__}"></span>
</div>
</div>
</div>
入力を直接定義できるため、非常に柔軟です。
私はすぐにそれを使用することができます
<div layout:include="templates::bsfield" th:with="fId='firstName'" th:remove="tag">
<div layout:fragment="bsinput">
<input type="text" th:field="*{__${fId}__}" th:disabled="${disabled}"/>
</div>
</div>
以上のプロトタイプスタイル
<div class="control-group" layout:include="templates::bsfield" th:with="fId='lastName'" th:remove="tag">
<label class="control-label" th:remove="all">Last Name</label>
<div class="controls" th:remove="tag">
<div layout:fragment="bsinput">
<input type="text" th:field="*{__${fId}__}" th:disabled="${disabled}"/>
</div>
</div>
</div>
両方のバリアントには、まだ定型文がたくさんあります。そこで、Playframework ヘルパーに触発された次のソリューションについて考えます。
<input type="text" th:bsfield="firstName" th:disabled="${disabled}"/>
作成するプロセッサを作成する
<div class="control-group"
th:classappend="${#fields.hasErrors('${fId}')}? 'error'">
<label class="control-label" th:for="${fId}"
th:text="#{model.__*{class.simpleName}__.${fId}}+':'">
FirstName </label>
<div class="controls">
<input type="text" th:class="${inputclass}" th:field="*{${fId}}" th:disabled="${disabled}"/>
<span class="help-inline" th:if="${#fields.hasErrors('${fId}')}"
th:errors="*{${fId}}"></span>
</div>
</div>
${fId}
この例の "firstname" の bsfield の値に置き換えます。その後、Thymeleaf はそれを再計算する必要があります ( setRecomputeProcessorsImmediately (true);
) プロトタイプについては、JS ソリューションを作成する必要があると思います。
これが本当に巧妙なのか、プロセッサの誤用なのかはわかりません。さらに、初心者がそのようなプロセッサを作成するのにどれくらいの時間が必要かはわかりません。現実的には 4 時間ですか、それとも数日ですか?
誰かが私にヒントを与えることができれば幸いです。