如何将缺少条目的自定义对象数组发布到 Struts2 操作 [英] How to post an array of custom objects with missing entries to Struts2 action

查看:24
本文介绍了如何将缺少条目的自定义对象数组发布到 Struts2 操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表格输入当数组大小未知时,建议使用 XWorkList 而不是 ArrayList中间有差距.

Tabular Inputs This suggests to use XWorkList instead of ArrayList, when the size of array is unknown & there are gaps in between.

但是 XWorkList 不是通用的 &根据 文档.

But XWorkList is not generic & it has no empty constructor, according to documentation.

我的问题是如何使用 XWorkList 或者有什么方法可以提交列表中缺少某些项目的 bean 列表?

My question is how to use XWorkList or is there any way to submit list of beans with some items missing in the list ?

示例 Html:

<input name="lst[0].name"/>
<input name="lst[3].name"/>
<input name="lst[4].name"/>

推荐答案

List 契约是一个有序集合.它不能缺少 indeces.关于 XWorkList 它只是列表的另一种实现,能够通过填充所需元素的间隙为指定索引创建新元素.add(int, Object)

A List contract is an ordered collection. It can't have missing indeces. About XWorkList it's just an other implementation of the list, capable of creating new elements for the specified index by filling gap for required elements. What is said for add(int, Object)

在此列表中的指定位置插入指定元素.移动当前在该位置的元素(如果有)和任何右边的后续元素(在它们的索引上加一).此方法保证有效,因为它会创建空 bean填补当前列表大小和请求的索引之间的空白启用要设置的元素.

Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices). This method is guaranteed to work since it will create empty beans to fill the gap between the current list size and the requested index to enable the element to be set.

在列表中创建新bean的另一种方法是使用类型转换.或者使用这个答案中的注释.

Another approach for creating new beans in the list is to use type conversion. Or using annotations like in this answer.

这篇关于如何将缺少条目的自定义对象数组发布到 Struts2 操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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