Spring Boot 表单提交后模式字段为空

wz3gfoph  于 2022-11-23  发布在  Spring
关注(0)|答案(1)|浏览(144)

我有模态来提交用户输入的评论。但是当用户输入提交按钮时,form-backing-object到达post结束点,但是使用模态输入的字段是空的。

<!-- Modal -->
                <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog"
                     aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                    <div class="modal-dialog modal-dialog-centered" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h5 class="modal-title" id="exampleModalLongTitle">Comment for approval</h5>
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                            <div class="modal-body">
                                <form action="" method="post">
                                    <textarea rows="5"
                                              placeholder="Comment..."
                                              th:field="*{processApproveComment}"
                                              th:value="${answeredQuestionnaire.processApproveComment}"
                                              class="form-control"
                                            name="processApproveComment">
                                                     </textarea>
                                </form>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                                                    <button type="submit" formaction="/release/process"  data-toggle="modal" data-target="#exampleModalCenter"
                                        class="btn btn-info" role="button">
                                    Approve
                                </button>
                                <input th:type="hidden" th:field="*{processApproveComment}"
                                       th:value="${answeredQuestionnaire.processApproveComment}"/>
                            </div>

                        </div>
                    </div>
                </div>

调用modal的位置是

<button type="submit" formaction="/release/process"  data-toggle="modal" data-target="#exampleModalCenter"
                                class="btn btn-info" role="button">
                            Approve
                        </button>

流程为:表单完成后,用户点击“Approve”按钮,触发模态,然后用户输入注解并按下“Approve”(来自模态),表单被提交。
当父表单的其他属性可用时,我没有只收到processApproveComment(使用模态设置),请有人指出这里的错误。
立柱终点为:

@PostMapping("/release/process")
    public String releaseProcess(Principal principal,
                                 Model model,
                                 @ModelAttribute("answeredQuestionnaire") AnsweredQuestionnaire answeredQuestionnaire){
//   answeredQuestionnaire does not have processApproveComment, but all others are available.
}

更新日期:

<div class="modal-body">
                                <form action="" method="post">
                                    <textarea rows="5"
                                              placeholder="Comment..."
                                              th:field="*{processApproveComment}"
                                              th:value="${answeredQuestionnaire.processApproveComment}"
                                              class="form-control"
                                            name="processApproveComment">
                                                     </textarea>
                                    <button type="submit" formaction="/release/process"  data-toggle="modal" data-target="#exampleModalCenter"
                                            class="btn btn-info" role="button">
                                        Approve
                                    </button>
                                </form>
                            </div>
zzoitvuj

zzoitvuj1#

因为按钮标记不在表单标记中
1.将按钮标签移至表单标签

相关问题