Thymeleaf - Submit from inside information <table>

Asked

Viewed 1,029 times

0

It is possible to give information ubmit from within a using Thymeleaf?

Example:

<form method="post" th:action="@{/receive}" th:object="${objeto}" >
    <input type="text" th:field="*{nome}"/>                  
    <table>
        <thead>
            <tr>
                <th>Produto</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>palavra de testes</td>
            </tr>
        </tbody>
    </table>            
    <button type="submit">Enviar dados</button>            
</form>

In this case when I click the Submit button, in my object only the name attribute will be populated, but in that same object I have an attribute of type List that I would like to popular from the values inside < table >. It is possible?

1 answer

0

I was able to send the information this way:

<form id="form1" th:action="@{/products}" th:object="${store}" method="post" th:method="POST" >
    <div>
        <input th:field="*{nome}" id="nome"/>
        <h5 class="center"> Product store items </h5>
        <table class="striped centered">
            <thead>
                <tr>
                    <th data-field="id"> Name </th>
                    <th data-field="name">Description </th>
                    <th data-field="price">Price </th>
                </tr>
            </thead>
            <tbody>
                <tr th:each="product, productStat : *{products}">
                    <td> <input type="text" th:field="*{products[__${productStat.index}__].name}" /> </td>
                    <td> <input type="text" th:field="*{products[__${productStat.index}__].description}" /> </td>
                    <td> <input type="text" th:field="*{products[__${productStat.index}__].price}" /> </td>
                    <td> <button type="submit" name="deleteProduct" class="btn-floating btn-small waves-effect waves-light" 
                                 th:value="${productStat.index}">
                            <i class="mdi-content-remove"></i></button>
                    </td>
                </tr>
            </tbody>
        </table>
        <button class=" btn waves-effect waves-light" type="submit" name="addProduct">Add product</button>
    </div>
    <button class=" btn waves-effect waves-light" type="submit" name="Enviar Informações">Submit</button>
</form>

Following this link: http://www.javaenthusiasm.com/using-thymeleaf-in-spring-projects-part-1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.