【问题标题】:Thymeleaf Spring Boot Webflow not submitting form properly th:each and buttonThymeleaf Spring Boot Webflow没有正确提交表单:每个和按钮
【发布时间】:2023-03-24 05:08:01
【问题描述】:

以下工作正常,没有问题

电话查询

<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 的表单允许单击按钮,但它只是刷新当前页面

确认客户.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>

我尝试将按钮更改为链接并使用 Spring from tags all 无济于事。

我开始认为这与在 th:each 期间分配给按钮的值有关。有什么想法吗?

【问题讨论】:

    标签: spring spring-mvc spring-boot thymeleaf spring-webflow


    【解决方案1】:

    form 标记中缺少 HTML action 属性。如果这需要包含变量,那么您需要包含 th:action 并按照文档中的示例进行操作。

    你也可以删除class="",因为它没有意义。

    【讨论】:

    • 我已经调查过了。做了一些调试后,我意识到
    • 我已经调查过了。在进行了更多调试后,我意识到 引起了问题。经过仔细检查,我需要将值更改为 th:value....
    【解决方案2】:

    改变

     <input type="hidden" value="${addresses.idaddresses}" name="idaddresses" />
    

     <input type="hidden" th:value="${addresses.idaddresses}" name="idaddresses" />
    

    thymeleaf 没有将值传递给控制器​​,因为它没有“th:value”

    【讨论】:

    • 您能否添加更多信息,说明您的答案如何解决相关问题?谢谢。
    猜你喜欢
    • 2014-06-17
    • 2018-09-24
    • 1970-01-01
    • 1970-01-01
    • 2010-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多