How to validate checkboxes in Spring MVC?

0

Any help I can learn is more than welcome!

I have the following spawn, created by me:

I want to validate the checkboxes that are shown in the image next to each of the ice cream tastes.

Then create this form:

<!-- Modal -->
    <div id="vasoModal" class="modal">
        <div class="modal-content">
            <h4 class="modal-title">Vasito</h4>
            <h6>Seleccione hasta dos gustos</h6>
            <form th:action="@{/pedido}" name="vasitoForm" method="post">
                <table class="tabla">
                        <tr th:each="gusto : ${gustos}">
                            <td class="flavour" th:text="${gusto.nombre}"></td>
                            <td><input class="single-checkbox" type="checkbox"/></td>
                        </tr>
                </table>
                <button type="submit" class="btn-submit">Enviar Pedido</button>
            </form>
        </div>

I'm using ThymeLeaf in the Front so the weird symbols come from there. It is quite similar to Angular JS, with some differences.

Well, this is the order controller that returns a view (for now empty) where the user's order should show, both the selected product (cup, cone, quarter, half or kilo of ice cream) and the selected tastes by the user.

@Controller
public class PedidoController {

    @RequestMapping(value = "/pedido", method = RequestMethod.POST)
    public String pedido(){

        return "pedido";
    }

I NEVER did this and so I ask: How should I do to validate checkboxes on the back-end?

The little glass that you see in the photo, for example, only admits up to two ice cream tastes, so you should validate that the user chooses up to two tastes and then grab those selected tastes to show them when he changes his view.

All classes are mapped in database.

    
asked by Nacho Zve De La Torre 23.11.2018 в 20:07
source

0 answers