better way for dynamic forms with Spring?

后端 未结 4 1526
旧时难觅i
旧时难觅i 2020-12-03 08:08

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

4条回答
  •  悲哀的现实
    2020-12-03 08:37

    I've found that also decorating with a GrowthList is necessary to avoid some errors when adding/setting items in JSP. (Also created a custom SpringList impl. that basically does the double decoration.)

    lineItems = GrowthList.decorate(ListUtils.lazyList(new ArrayList(), FactoryUtils.instantiateFactory(LineItem.class)));
    

    I agree. The problem is certainly removing items.

    What you can do is use the spring marker syntax in the html. So if you remove an item (at index 2 for example) from the list using javascript, you would then mark that index with:

    
    

    Then when the form is submitted spring will see the marker and put in an empty item (based on the lazylist factory) for lineItems2 instead of ignoring it.

提交回复
热议问题