spring webflow使用新项目提交数组 [英] spring webflow submit array with new items

查看:121
本文介绍了spring webflow使用新项目提交数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用spring webflow提交包含新项目的数组。对于eaxmple,如果myList的大小为3,然后我添加第4项,则提交失败。

I'm trying to submit array with new items using spring webflow. For eaxmple if myList has size 3 and then i add 4th item then submit fails.

<c:forEach items="${myList}" var="item" varStatus="status">
  <tr>
    <td>
       <input type="number" readonly class="form-control" value="${item.a}" name="myList[${status.index}].a"/>
    </td>
    <td>
      <input type="number" class="form-control" value="${item.b}" name="myList[${status.index}].b"/>
    </td>
    <td class="text-center">
      <i class="fa fa-trash delete" data-link="${flowExecutionUrl}&_eventId=deleteItem&itemId=${item.id}"></i>
    </td>
  </tr>
</c:forEach> 

<tr>
  <td>
    <input type="number" readonly class="form-control" value="1234" name="myList[3].a"/>
  </td>
  <td>
    <input type="number" class="form-control" value="5678" name="myList[3].b"/>
  </td>
  <td class="text-center">
    <i class="fa fa-trash delete"></i>
  </td>
</tr>

那么如何提交这样的表格?

So how to submit such form?

推荐答案

因为您提供数据仓的ArrayList具有预定义的固定大小,并且无法接受新条目。

because the ArrayList you are providing the databinder has a predefined fixed size and cannot accept new entries.

在尝试向流程中的数据绑定器添加任何新条目之前,需要使用AutoPopulatingList(位于spring-core.jar中)包装ArrayList ... 。(或者只是在你的pojo上使用AutoPopulatingList来避免包装器方法)。

You need to wrap your ArrayList with an AutoPopulatingList (located in spring-core.jar) before attempting to add any new entries to the data binder in your flows.... (or simply use an AutoPopulatingList on your pojo to avoid wrapper method).

样本转换方法:

import org.springframework.util.AutoPopulatingList;

//跳过类定义

        public <T> List<T> wrapListWithAutoPopulatingList(List<T> list, Class<?> pojoClazz)  {

            List<T> apl = new AutoPopulatingList(list, pojoClazz ) ;
            return apl;
        }

Java Doc:


简单列表包装类,允许元素在请求时自动填充
。这对于绑定到列表的数据
特别有用,允许以及时方式创建元素并将其添加到
列表中。

Simple List wrapper class that allows for elements to be automatically populated as they are requested. This is particularly useful for data binding to Lists, allowing for elements to be created and added to the List in a "just in time" fashion.

注意:此类不是线程安全的。要创建线程安全的版本,
使用java.util.Collections.synchronizedList实用程序方法。

Note: This class is not thread-safe. To create a thread-safe version, use the java.util.Collections.synchronizedList utility methods.

受Commons Collections的LazyList启发。

Inspired by LazyList from Commons Collections.

同时,请注意initBinder上的 autoGrowCollectionLimit 属性。默认最大值为256个条目。如果您需要更多(或更少),可以调整此项。见

Also, please be aware of the 'autoGrowCollectionLimit' property on the initBinder. The default max value is 256 entries. This can be adjusted if you need more (or less). See

无法发布包含多个(超过256个)值的表单

这篇关于spring webflow使用新项目提交数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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