How to insert value into Set collection in Struts 2

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

Here is my action (I ruled out the non-essential part)

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

}

Here is my model Team(I excluded the non-essential part)

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

Here is my part of the jsp

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

Now the problem is that I cannot insert the correct value into this collection Setin ModelDriven, this will throw an exception. Could you tell me what to write in the JSP file, so I can insert the value into the collection Setin my model?

+2
source share
1 answer

Set Collection, .

@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

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

. .

+1

Source: https://habr.com/ru/post/1664899/


All Articles