使用Spring的动态表单更好的方法? [英] better way for dynamic forms with Spring?

查看:95
本文介绍了使用Spring的动态表单更好的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在使用SpringMVC和Spring表单时是否有更简单/更好的方法来处理动态表单(通过js向dom添加表单项)?

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?

具有包含许多LineItem的Invoice对象的映像。

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>

要添加LineItems,我有一些js计算新索引并将其添加到DOM。删除LineItem时,我当前必须重新编号所有索引,这是我想避免的部分,是否可能?

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?

推荐答案

<我已经实现了一个教程,可以帮助您在客户端使用jQuery解决这个问题,并为您创建支持对象的弹出自动填充列表。

I've implemented a tutorial that might help you solve this using jQuery on the client side and Springs AutoPopulating list for you form backing objects.

http://eggsylife.co.uk/2009 / 11/30 / spring-forms-dynamic-lists-and-ajax /

编辑
来自Webarchive的链接 https://web.archive.org/web/20160729163958/http://eggsylife.co.uk/2009/11/30/spring-forms-dynamic-lists-and-ajax/

这篇关于使用Spring的动态表单更好的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆