两个带有Thymeleaf的单选按钮组,使用th:field但覆盖名称

问题描述

我正在动态生成表单上的输入。我所有的输入选择都将保存到Pizza对象的配料中。我有两个用于选择面团和调味料的单选按钮,因为从该配料类别中只能选择一个。每个类别的选择都需要保存到成分中。我从一个单选组中所做的选择将覆盖另一个,因为th:field会覆盖名称,但是两个按钮组都需要对应才能提交到同一字段。如何在不覆盖另一个选择的情况下从这两个选择中进行选择,同时仍然确保将输入保存到相应的字段(将选择的输入添加到比萨的食材中)

<form autocomplete="off"
      th:action="@{/processOrder}"
      th:object="${pizza}"
      method="post">

    Select dough type:
    <div th:each="dough : ${doughs}">
        <input type="radio" id="doughSelection1" th:value="${dough.id}" th:id="${dough.id}"
               th:field="*{ingredients}" name="dough"> <label for="doughSelection1">[[${dough.name}]]</label>
    </div>

    Select sauce type:
    <div th:each="sauce : ${sauces}">
        <input type="radio" id="sauce" th:value="${sauce.id}" th:id="${sauce.id}"
               th:field="*{ingredients}" name="sauce" th:field="${pizza.ingredients}"><label for="sauce">[[${sauce.name}]]</label>
    </div>

    Check Protein type:
    <div th:each="protein : ${proteins}">
        <input type="checkBox" id="protein" th:value="${protein.id}"
               th:field="*{ingredients}"><label for="protein">[[${protein.name}]]</label>
    </div>

    Check Veggie type:
    <div th:each="veggie : ${veggies}">
        <input type="checkBox" th:id="${veggie.id}" th:value="${veggie.id}"
               th:field="*{ingredients}"><label th:for="${veggie.id}">[[${veggie.name}]]</label>
    </div>
</form>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)