如何在Struts 2中的Set集合中插入值 [英] How to insert a value into Set collection in Struts 2

查看:89
本文介绍了如何在Struts 2中的Set集合中插入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Struts2做一个项目,我在分配集合时遇到问题。

I am doing a project using Struts2 and I have a problem assigning a set collection.

这是我的行动(我删除了无关的部分)

Here's my Action (I eliminated the irrelevant part)

public class TeamAction extends BaseAction implements ModelDriven<Team>
{
 Team team=new Team();

}

这是我的模特团队(我删除了无关的部分)

Here's my model Team (I eliminated the irrelevant part)

private TeamId id;
private Set students = new HashSet(0);

这是我的JSP部分

<input type="text" name=team.student[0].id />

现在的问题是我无法在此集中插入正确的值通过 ModelDriven 收集,它会抛出异常。你能告诉我在JSP文件中写什么,所以我可以在我的模型中向 Set 集合插入一个值吗?

Now the problem is I can't insert the right value into this Set collection in by ModelDriven, it will throw a exception. Could you please tell me what to write in JSP file, so I can insert a value to Set collection in my model?

推荐答案

设置是一个集合和任何其他集合可能是由财产索引。

Set is a Collection and as any other collection could be indexed by a property.

@Element(value = Student.class)
@Key(value = Integer.class)
@KeyProperty(value = "id") 
@CreateIfNull(value = true)
private Set<Student> students = new HashSet(0);
//getter and setter, also for Student class that should have Integer id.

JSP中的

in JSP

<s:iterator value="students " var="student">
  <s:textfield name="students(%{#student.id}).name" />
</s:iterator>

有关此内容的更多信息,请参阅通过该集合的属性索引集合

More about this see in Indexing a collection by a property of that collection.

这篇关于如何在Struts 2中的Set集合中插入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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