0

I have a problem with this method, I need to update the value of the "procesado" variable (the variable it starts being from false because its boolean type), I can select one or more checkboxes and when I click the button(Procesar), the value of the variable should change to true.

the problem is when i select the checkboxes that i can't update and display the results

This is my controller:

@RequestMapping(value = "/consulta/{id}", method = RequestMethod.PUT)
    public String update(@RequestBody Usuario user, @PathVariable(value="id") List<Usuario> id) {


        if(id != null) {
            for(Usuario idInt: id) {
                Usuario idValor= idInt;
                user.setProcesado(true);
                iusuarioServices.save(user);

            }
        }
        return "consulta";

    }

This is my html

<form action="@{/consulta/{id}}">
        <table>

            <thead>
                <tr>
                    <th>ID</th>
                    <th>Nombre</th>
                    <th>Apellido</th>
                    <th>Procesado</th>
                    <th>Accion</th>
                </tr>

            </thead>
            <tbody>
                <tr th:each="usuarios: ${usuarios}">
                    <td th:text="${usuarios.id}"></td>
                    <td th:text="${usuarios.nombre}"></td>
                    <td th:text="${usuarios.apellido}"></td>
                    <td th:text="${usuarios.procesado}"></td>





                    <td><input type="checkbox" th:name="procesado" th:value="${usuarios.id}"></td>


                </tr>


            </tbody>

            <tr>
                <td><input type="submit" value="Procesar" /></td>
            </tr>

        </table>
    </form>

enter image description here

  • do you mean you want the checkbox to be checked or unchecked depending on the value of procesado? if that's what you want you need to add `th:checked="${usuarios.procesado}"` in the checkbox – Ryan Guamos Apr 29 '20 at 20:07
  • Yes, i need to do that, but i stil have the same problem http://localhost:8090/@%7B/consulta/%7Bid%7D%7D?procesado=on – Andres Alfonso Apr 29 '20 at 20:16
  • I think the problem lies in your form. since you are using thymeleaf you should use th tags your form should be `
    ` and replace attribute `method` in your controller to `method = RequestMethod.POST` check this [PUT AND DELETE](https://stackoverflow.com/questions/13629653/using-put-and-delete-methods-in-spring-mvc)
    – Ryan Guamos Apr 29 '20 at 20:38

0 Answers0