2014-06-12 4 views
2

Struts2를 사용하여 프로젝트를 수행하고 있으며 컬렉션을 할당하는 데 문제가 있습니다. 여기 Struts 2의 Set 컬렉션에 값을 삽입하는 방법

내 작업의

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

가 여기 내 JSP 부분이다 (필자는 관련이없는 부분을 제거)

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

} 

여기 내 모델 Team이다 (필자는 관련이없는 부분을 제거)

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

이제 문제는이 값에 올바른 값을 삽입 할 수 없다는 것입니다. Set 컬렉션을 ModelDriven에 넣으면 예외가 발생합니다. 내 모델에 Set 콜렉션에 값을 삽입 할 수 있도록 JSP 파일에서 작성할 내용을 알려주시겠습니까?

+0

참조 : http://stackoverflow.com/q/23470075/1700321. –

답변

1

SetCollection이며 다른 모든 모음은 속성으로 색인 될 수 있습니다. 이것에 대해 JSP에서

@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. 

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

더는 Indexing a collection by a property of that collection에서 참조하십시오.

+0

우리가'(% {# student.id})를 사용하는 이유는''를 사용할 수 있습니다. – xrcwrn

+0

List에 대한 입력을 얻기 위해 동일한 notatin 'In Jsp'를 사용할 수 있습니까? – xrcwrn

+0

@xrcwrn 직접 시도해 보셨습니까? 나는 그것이 당신에게 정확한 대답을 주어야한다고 생각합니다. –

관련 문제