TransWikia.com

¿Cómo enviar una tabla dinámica con Thymeleaf a un Controller de Spring?

Stack Overflow en español Asked by Ricardo López on January 24, 2021

Saludos amigos de StackOverflow necesito su apoyo con el requerimiento que tengo que implementar, dejen les explico. Estoy construyendo una tabla dinámica con Thymeleaf, la cual voy a mostrar los registros al usuario que va a poder actualizar. Yo necesito volver a mandar esa tabla dinámica a un Controller y recibir esa peticion como un ArrayList o List y realizar la actualización correcta dentro de mi controller.

Mi pregunta concreta seria..¿Cómo puedo enviar una tabla dinámica hecha con Thymeleaf desde un formulario a un Controller de Spring?

Esta es la tabla que quiero mandar introducir la descripción de la imagen aquí

y este es el codigo con el cual la construyo:

HTML

<form id="formListado" th:Object="${beneficiariosArray}" method="POST" onsubmit="actualizarFolio(this)">
            <!--Tabla de Contenido-->
            <div class="table-responsive-sm tabla_container ">
                <!--div para el scroll en la tabla-->
                <div class="scroll_div">
                    <table id="tablaResultado" class="table table-hover table-sm">
                        <thead class="thead-dark">
                            <tr class="">   
                                <th scope="col">Entidad</th>
                                <th scope="col">Programa</th>
                                <th scope="col">IDCaptura</th>
                                <th scope="col">Folio</th>
                                <th scope="col">Trámite</th>
                                <th scope="col">IDPadron/IDUnico</th>
                                <th scope="col">Nombre</th>
                                <th scope="col">Apellido Paterno</th>
                                <th scope="col">Apellido Materno</th>
                                <th scope="col">Fecha Captura</th>
                                <th scope="col">Usuario Captura</th>
                                <th scope="col">Estatus</th>
                                <th scope="col">Reactivar</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr th:each="beneficiario:${beneficiarios}">
                                <td scope="row" th:text="${entidad}">AGUASCALIENTES</td>
                                <td scope="row" th:text="${programa}">SIN PROGRAMA</td>
                                <td scope="row" th:text="${beneficiario.idFormato}"></td>
                                <td scope="row" th:text="${beneficiario.folio}">89900879</td>
                                <td scope="row" th:text="${tramite}">Incorporación</td>
                                <td scope="row" th:text="${beneficiario.idUnico}">90003438954</td>
                                <td scope="row" th:text="${beneficiario.nombre}">Maribel</td>
                                <td scope="row" th:text="${beneficiario.apPaterno}">Angeles</td>
                                <td scope="row" th:text="${beneficiario.apMaterno}">Moreno</td>
                                <td scope="row" th:text="${fechaCaptura}">04/09/2020</td>
                                <td scope="row" th:text="${beneficiario.usuarioCaptura}">MARIBEL.ANGELES</td>
                                <td scope="row" th:text="${beneficiario.estatus}">2</td>
                                <td scope="row" ><p style="color: green;" th:text="${itsOK}">OK</p><p style="color: red;" th:text="${itsBAD}">BAD</p></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <!--div para los botones-->
                <div class=" row d-flex justify-content-end">
                    <button type="submit" class="btn btn-success">ACTUALIZAR</button>
                    <button type="button" class="btn btn-danger">CANCELAR</button>
                </div>
            </div>
            <!--Fin de Tabla-->
        </form>

Y yo uso la variable "beneficiarios" que mando desde otro Controller para que el th:each construya mi tabla con ese arreglo. Esta tabla la estoy enviando a otro controller mediante un formulario con el object de nombre "beneficiariosArray":

JAVA – SPRINGBOOT

@RequestMapping(value= "/actualizarFolios", method = RequestMethod.POST)
public String actualizarTodosFolios(@ModelAttribute(value="beneficiariosArray") ArrayList<PeticionActualizarFolios> peticion, Model model)  throws SQLException, ParseException{
    System.out.println(peticion.toString());
    return "redirect:/inicio/programas/buscarFolios";
}

Me estoy quebrando la cabeza porque no sé como hacer un th:field="*{beneficiariosArray.add(beneficiario)}" para llenar el Object que defino en mi formulario al mismo tiempo que se va construyendo la tabla dinamica. Otras formas que he visto es construir un Array en mi javascript y asociar la tabla a ese Array y despues setearlo al formulario y hacer un action a mi Controller pero no se como se haga. Porfavor espero alguien pueda ayudar. Saludos

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP