Answer the question
In order to leave comments, you need to log in
How to pass variable value (id) to modal window in thymeleaf?
Hello!
In the thymeleaf template, I display a loop with data.
For example, a code snippet:
......
<tr th:each="user: ${user}">
<td th:text="${user.userId}">User ID</td>
<td>
<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#sendData">Отправить</button>
</td>
......
</tr>
......
<form th:action="@{'/users/' + ${user.userId}}" method="post">
<button type="submit" class="btn btn-warning float-right" data-dismiss="modal">Отправить</button>
</form>
Answer the question
In order to leave comments, you need to log in
First, Thymeleaf doesn't have modal windows. Your modal is from Bootstrap. Second, it's important to understand that Thymeleaf is a templating engine, it runs on the backend, while Bootstrap runs on the frontend. Backend and frontend are two different programs written in different languages and running on different computers at different times. So you either have to spawn different modals on each iteration in the template engine loop, or you have to write javascript code that will pass data from the pressed button to a single modal window. Naturally, the second option makes more sense.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question