這是我使用重新填充ArrayList
重新填充的ArrayList使用Struts 2
<form method = "POST" action = "addItemsToTemplate">
<s:iterator value = "myQuestions" var = "quizItem" status="key">
<s:textfield name = "quizItem.question"/>
</s:iterator>
<input type = "submit" value = "submit"/>
</form>
形式這是動作類
public class QuizTest extends ActionSupport{
public String execute(){
List<Question> q= myQuestions;
System.out.println(myQuestions);
return "success";
}
public String populateQuestions(){
//more code here
}
public void setMyQuestions(List<Question> myQuestions) {
this.myQuestions = myQuestions;
}
private List<Question> myQuestions = new ArrayList<Question>();
}
哪裏myQuestions
是問對象列表。提交後,這給我一個錯誤
Unexpected Exception caught setting 'quizItem.question' on 'class quiz.actions.QuizTemplateAction: Error setting expression 'quizItem.question' with value '[Ljava.lang.String;@1b3409f'
和System.out.println(myQuestions);
打印一個空列表。但myQuestions
已經被從另一個用這種方法populateQuestions()
填充,提交表單
btw問題是一個抽象類 – user962206 2013-03-27 04:57:30
我在哪裏罰款xwork轉換屬性文件? – user962206 2013-03-27 04:58:27
當我做這個私人列表時0123tmyQuestions = new ArrayList();它給了我一個空值 –
user962206
2013-03-27 05:03:30