在我的 Action 课程中,我有一个Questions
. 我想从视图中填充。
public class MyQuizTest extends ActionSupport {
public String addItemsToTemplate(){
List<Question> q= myQuestions;
System.out.println(q);
return "success";
}
public List<Question> getMyQuestions() {
return myQuestions;
}
public void setMyQuestions(List<Question> myQuestions) {
this.myQuestions = myQuestions;
}
private List<Question> myQuestions;
}
这是问题课
public class Question{
public boolean isChosen(){
retrun this.chosen
}
public void setChosen(boolean chosen){
this.chosen = chosen;
}
private boolean chosen;
}
这是处理该问题的表格
<form method = "GET" action = "addItemsToTemplate">
<s:iterator value = "myQuestions" status="key" var = "questionItem">
<s:checkbox name = "myQuestions[%{#key.index}].chosen" label="Check Me for testing"/>
</s:iterator>
</form>
此方法处理表单
public String addItemsToTemplate(){
List<Question> q= myQuestions;
System.out.println(q);
return "success";
}
提交后,myQuestions
返回一个null
. 这是为什么?我想确定是否选择了相应的问题。