P
P
P_Alexander2020-05-06 22:56:04
Java
P_Alexander, 2020-05-06 22:56:04

Why do I get data from two forms in the controller?

Good evening, there are two forms, each form has its own submit mapped by the form ID, when I click on any of them I get data from two forms in the controller, why?
controller

@RequestMapping(value = "/ceo", method = RequestMethod.POST)
    public String postCeo(@ModelAttribute("rcf") RemoveCustomerForm rcf, @ModelAttribute("ctm") CustomerTransferModel ctm, Model model) {
        logger.debug("RemoveCustomerForm -- " + rcf.toString()); //--- тут будут данные из одной формы
        logger.debug("CustomerTransferModel -- " + ctm.toString()); // --- и тут будут данные из второй формы за раз

        model.addAttribute("customers", prepareCustomer());
        model.addAttribute("searchPassportForm", searchPassportForm);
        return "ceo";
    }

page
<th:block th:each="customer: ${customers}">
                <div>
                    <span th:text="${customer.name}"></span>
                    <span th:text="${customer.email}"></span>
                    <span><a th:href="@{/ceo/customer/{login}(login=${customer.login})}" th:text="${customer.login}"></a></span>
                    <span th:text="${customer.role.role}"></span>
                    <span th:text="${customer.statusAccount}"></span>
                    <form th:id="${customer.statusAccount} + '' + ${customer.id}" th:action="@{/ceo}"  method="post">
                        <input type="hidden" th:form="${customer.statusAccount} + '' + ${customer.id}" name="login" th:value="${customer.login}">
                        <input type="hidden" th:form="${customer.statusAccount} + '' + ${customer.id}" name="statusAccount" th:value="${customer.statusAccount}">
                        <input type="hidden" th:form="${customer.statusAccount} + '' + ${customer.id}" name="action" value="block">
                        <input type="submit" th:form="${customer.statusAccount} + '' + ${customer.id}" value="Block">
                    </form>
                    <form th:id="${customer.name}" th:action="@{/ceo2}" method="post">
                        <input type="hidden" th:form="${customer.name}" name="login" th:value="${customer.login}">
                        <input type="hidden" th:form="${customer.name}" name="action" value="remove">
                        <input type="submit" th:form="${customer.name}" value="Remove">
                    </form>
                </div>
            </th:block>

Any help thanks.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question