I am developing a simple Planning Poker MVC app using Java 11, Spring Boot 2.1.2 and Thymeleaf Spring 5.
The attached image shows the main HTML page. After login, the user submits a score. The request goes to a controller method, pasted below, where the score is persisted to a database. Then, the whole set of scores for the group are retrieved from the database as a list. Both the user's individual score and the list of group scores are added to the model and the user is forwarded to the poker.html page
@PostMapping("/score")
public String submitScores(@Valid SimplePoker simplePoker, BindingResult result, Model model) {
SimplePoker poker = simplePokerRepository.save(simplePoker);
model.addAttribute("poker_score", poker);
Iterable<SimplePoker> scores = simplePokerRepository.findAll();
model.addAttribute("scores", scores);
return "poker";
}
On the poker.html page, a table is generated using a standard Thymeleaf pattern, as shown below: -
<div class="container" th:if="${not #lists.isEmpty(scores)}">
<table class="table table-striped table-hover table-bordered table-responsive-md">
<thead class="thead-dark">
<tr>
<th class="text-center, align-middle">Name</th>
<th class="text-center, align-middle">Planning</th>
<th class="text-center, align-middle">Business Risk</th>
<th class="text-center, align-middle">Chance of Failure</th>
<th class="text-center, align-middle">Total Risk</th>
</tr>
</thead>
<tbody>
<tr th:each="score: ${scores}">
<td th:text="${score.name}"></td>
<td th:text="${score.planningScore}"></td>
<td th:text="${score.risk1Score}"></td>
<td th:text="${score.risk2Score}"></td>
<td th:text="${score.risk3Score}"></td>
</tr>
</tbody>
</table>
</div>
This all works well, but of course the table only represents the results at the time the user made the request. I would like to add an 'Update Table' button just below the table (yellow highlighted area) that the user can click that will fetch a fresh set of data and update the table on the page with the latest results. As I am primarily a back-end developer, I am struggling a bit here and would really appreciate some guidance.
I think I would be able to create a crude solution, where clicking the button simply refreshes the entire page, but it would much more smooth to be able to update just the table. The icing on the cake would be if the table auto-updated every few seconds, omitting the need for the user to click the button. But as a first step, implementing a button to update the table would be brilliant.
Many thanks in advance for reading my post and for any assistance offered.
