What I wonder is if there's a easier/better way to handle dynamic forms (adding form items to the dom via js) when using SpringMVC and Spring forms?
Imaging having an Invoice object that have many LineItems.
public class Invocie {
private List LineItems;
public Invoice() {
lineItems = ListUtils.lazyList(new ArrayList<LineItem>(), FactoryUtils.instantiateFactory(LineItem.class));
}
}
To show the items belonging to an Invoice I currently use
<forEach items="${invoice.lineItems}" varStatus="i">
<form:input path="lineItems[${i.index}].productName" />
</c:forEach>
To add LineItems I have some js that calculates the new index and adds that to the DOM. When deleting a LineItem i currently have to renumber all the indexes and that's the part I'd like to avoid, is it possible?