0

I want to fill a list of applications for a university in the frontend. Each entry is supposed to hold two buttons: one for accepting the application and one for rejecting it. I created one form for each submit-button each.

<div class="container">
            <div class="row">
                <div class="col-12">
                    <table class="table table-hover">
                        <thead>
                        <tr>
                            <th scope="col"></th>
                            <th scope="col">Firstname</th>
                            <th scope="col">Lastname</th>
                            <th scope="col">Grade</th>
                            <th scope="col">NC</th>
                            <th scope="col">Course</th>
                            <th scope="col">Certificate</th>
                            <th scope="col">Recommendation</th>
                            <th scope="col">Decision</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="applicationOpen, rowStat: ${lstOpApplications}">
                            <th th:text="${rowStat.count}">1</th>
                            <td th:text="${applicationOpen.firstname}">firstname</td>
                            <td th:text="${applicationOpen.lastname}">lastname</td>
                            <td th:text="${applicationOpen.highschool_grade}">grade</td>
                            <td th:text="${applicationOpen.nc}">nc</td>
                            <td th:text="${applicationOpen.name}">coursename</td>
                            <td th:text="${applicationOpen.highschool_certificate}">certificate</td>
                            <td th:text="${applicationOpen.document}">recommendation</td>
                         

                            <td>
                                <form action="#" th:action="@{/Bewerberubersicht}" th:object="${decisionForm}" method="post">
                                    <input type="hidden" name="application_id" th:field="*{application_id}" value=${applicationOpen.id}"/>
                                    <input type="hidden" name="decision" th:field="*{decision}" value=1/>
                                    <button type="submit" class="btn btn-success"><i class="fas fa-edit"></i>Accept</button>
                                </form>
                                <form action="#" th:action="@{/Bewerberubersicht}" th:object="${decisionForm}" method="post">
                                    <input type="hidden" name="application_id" th:field="*{application_id}" value=${applicationOpen.id}/>
                                    <input type="hidden" name="decision" th:field="*{decision}" value=2/>
                                    <button type="submit" class="btn btn-danger"><i class="fas fa-edit"></i>Reject</button>
                                </form>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

When I look in the Browser's Dev-Tools I can see that the content of the POST-request is

application_id: ""
decision: ""

When I replace value=${applicationOpen.id} with e.g. value=5 it is still empty. Hence, it should not be a problem with applicantOpen. Also, the list in the frontend is being filled just fine, so all of that should work. I first thought is is a problem with the DecisionForm class, but it seems my subsequent problems are caused by the issue described here.

1
  • Did you try with adding the quotes? So value="2" instead of value=2 for example? Commented Nov 24, 2020 at 8:05

1 Answer 1

0

The th:field attribute overrides content of name and value attributes. The decisionForm object seems to have empty fields so all forms have empty values.

Basically using th:object with th:field is convenient when you need to have your form prepopulated with values. It establishes initial state of your form, not the target. Using them makes sense for single form, not for multiple forms in loop with varying values.

In your case: please remove both th:object and th:field attributes. Instead use value="1" or value="2" for decision input, and th:value="${applicationOpen.id}" for application_id input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.