Thymeleaf Spring 引导 Webflow 未正确提交表单 th:each 和按钮
Thymeleaf Spring Boot Webflow not submitting form properly th:each and button
以下工作正常,没有问题
电话查找
<form class="" autocomplete="off" th:object="${user}" method="post" role="form">
<div class="row" style="margin-top: 20px">
<div class="input-field col s8 offset-s2">
<input th:field="*{phoneNo}" id="icon_telephone" type="number" class="validate" style="height: 160px !important; text-align: center; font-size: 100px" data-length="10">
<label for="icon_telephone" style="font-size: 40px">Telephone</label>
</div>
</div>
<div class="row">
<button type="submit" class="btn btn-primary btn-block green darken-1 col s8 offset-s2" name="_eventId_phoneEntered" style="height: 100px; font-size: 33px;">Lookup Phone Number</button>
</div>
</form>
但是,带有 thymeleaf th:each 的表单允许单击按钮,但它只会刷新当前页面
confirmCustomer.html
<div class="row">
<div class="col s12 m9">
<div th:each="addresses: ${addresses}">
<form class="" autocomplete="off" th:object="${address}" method="post" role="form">
<h1 th:text="${addresses.street1}"></h1>
<h1 th:text="${addresses.apt}"></h1>
<h1 th:text="${addresses.special}"></h1>
<button type="submit" class="btn btn-primary btn-block green darken-1 col s8 offset-s2" name="_eventId_useAddress">Lookup Phone Number</button>
<input type="hidden" value="${addresses.idaddresses}" name="idaddresses" />
</form>
</div>
删除所有内容,只留下表单标签和按钮,让页面继续进行流程的下一部分。
<form class="" autocomplete="off" th:object="${address}" method="post" role="form">
<button type="submit" class="btn btn-primary btn-block green darken-1 col s8 offset-s2" name="_eventId_useAddress">Lookup Phone Number</button>
</form>
我试过将按钮更改为 link 并使用标签中的 Spring 都无济于事。
我开始认为这与 th:each 期间分配给按钮的值有关。有什么想法吗?
您的 form
标签中缺少 HTML action
属性。如果这需要包含变量,那么您需要包含 th:action
并按照文档中的示例进行操作。
您也可以删除 class=""
,因为它没有意义。
改变
<input type="hidden" value="${addresses.idaddresses}" name="idaddresses" />
至
<input type="hidden" th:value="${addresses.idaddresses}" name="idaddresses" />
thymeleaf 没有将值传递给控制器,因为它没有 "th:value"
以下工作正常,没有问题
电话查找
<form class="" autocomplete="off" th:object="${user}" method="post" role="form">
<div class="row" style="margin-top: 20px">
<div class="input-field col s8 offset-s2">
<input th:field="*{phoneNo}" id="icon_telephone" type="number" class="validate" style="height: 160px !important; text-align: center; font-size: 100px" data-length="10">
<label for="icon_telephone" style="font-size: 40px">Telephone</label>
</div>
</div>
<div class="row">
<button type="submit" class="btn btn-primary btn-block green darken-1 col s8 offset-s2" name="_eventId_phoneEntered" style="height: 100px; font-size: 33px;">Lookup Phone Number</button>
</div>
</form>
但是,带有 thymeleaf th:each 的表单允许单击按钮,但它只会刷新当前页面
confirmCustomer.html
<div class="row">
<div class="col s12 m9">
<div th:each="addresses: ${addresses}">
<form class="" autocomplete="off" th:object="${address}" method="post" role="form">
<h1 th:text="${addresses.street1}"></h1>
<h1 th:text="${addresses.apt}"></h1>
<h1 th:text="${addresses.special}"></h1>
<button type="submit" class="btn btn-primary btn-block green darken-1 col s8 offset-s2" name="_eventId_useAddress">Lookup Phone Number</button>
<input type="hidden" value="${addresses.idaddresses}" name="idaddresses" />
</form>
</div>
删除所有内容,只留下表单标签和按钮,让页面继续进行流程的下一部分。
<form class="" autocomplete="off" th:object="${address}" method="post" role="form">
<button type="submit" class="btn btn-primary btn-block green darken-1 col s8 offset-s2" name="_eventId_useAddress">Lookup Phone Number</button>
</form>
我试过将按钮更改为 link 并使用标签中的 Spring 都无济于事。
我开始认为这与 th:each 期间分配给按钮的值有关。有什么想法吗?
您的 form
标签中缺少 HTML action
属性。如果这需要包含变量,那么您需要包含 th:action
并按照文档中的示例进行操作。
您也可以删除 class=""
,因为它没有意义。
改变
<input type="hidden" value="${addresses.idaddresses}" name="idaddresses" />
至
<input type="hidden" th:value="${addresses.idaddresses}" name="idaddresses" />
thymeleaf 没有将值传递给控制器,因为它没有 "th:value"