内のエンティティとタグを「選択」の使用:Spring Data JPA
の私はこのようになりますselectタグでフォームを作成していThymeleaf
<form th:object="${version}" method="post" class="form-horizontal">
...
<div class="control-group" th:classappend="${#fields.hasErrors('product')} ? 'error'">
<label class="control-label" for="product" th:text="#{version.product}">Product</label>
<div class="controls">
<select id="product" th:field="*{product}">
<option value="" th:text="#{common.select.prompt}"></option>
<option th:each="p : ${productList}" th:value="${p.id}" th:text="${p.name}"></option>
</select>
<span class="help-inline" th:errors="*{product}"></span>
</div>
</div>
...
</form>
DomainClassConverter
クラスI実体Product
にid
を選択した自動変換するのに役立ちますフォームを提出してください。 product
も私はVersion
クラスにproduct
フィールド上@NotNull
を使用しています(NOT NULLでなければなりません
私が持っている問題 - 。私はデータを編集するために戻ってきたときに、Product
が選択されていない
。 <-- p.s. is not a sad smile
その後、
<select id="product" th:field="*{product.id}">
<option value="" th:text="#{common.select.prompt}"></option>
<option th:each="p : ${productList}" th:value="${p.id}" th:text="${p.name}"></option>
</select>
<span class="help-inline" th:errors="*{product.id}"></span>
それは私がそれを編集するために戻ってきたときに選択した状態になるが、バリデータは動作しません(0123:私はこのようなselect
(th:field
とth:errors
)を変更した場合選択されたIDがnull
であっても、は常にインスタンス化されます。
非常に一般的なシナリオ(リストからエンティティを選択)のように見えますが、見栄えの良い例は見つかりません。秘密の知識を共有してください。
編集に戻るとどういう意味ですか? –
私はバージョンエンティティの作成と編集に同じページを使用します –