I am not quite sure how to approach this problem. I have a table rendered by datatables populated with product information. I am trying to figure out a form where I can insert the quantity and discount values and then save either the selected fields or fields where the quantity > 0. Then bind the table data to a set or a list.
However, I am not quite sure how to write the bindings. I have read over this question here but it didn't seem quite the same in that I don't think I could use an index as there could a large amount of products and therefore potentially a large amount of nulls in the response. Any help would be appreciated.
Product.java
@Entity
@Table(name="products")
public class Product {
@Getter
@Setter
@Id
private Long productId;
@Getter
@Setter
private Long productName;
}
QuoteForm.java
public class QuoteForm {
@Getter
@Setter
private Long quoteId;
@Getter
@Setter
private Long contactId;
@Getter
@Setter
private Set<ProductEntry> products;
}
ProductEntry.java
public class ProductEntry {
@Getter
@Setter
private TempProduct product;
@Getter
@Setter
private Long quantity;
@Getter
@Setter
private float discount;
}
form.html
<form id="productTable" th:object="${quoteForm}">
<input type="number" th:field="*{contactId}"></input>
<table id ="productList"
class="table table-striped table-bordered"
cellspacing="0"
width="100%">
<thead>
<tr>
<th>Name</th>
<th>Quantity</th>
<th>Discount</th>
</tr>
</thead>
<tbody>
<tr th:each="product : ${productData.getProducts()}">
<td name="?">
<a th:text="${product.getProductName()}"
th:href="@{|/product/records/${product.getProductId()}|}">
</a>
</td>
<td>
<input type="number"
name="?"
th:field="*{products.quantity}">
</input>
</td>
<td>
<input type="number" name="?" th:field="*{products.discount}"></input>
</td>
</tr>
</tbody>