如有任何帮助,将不胜感激:
在我的JSP中,我有一个动态问题列表,每个问题都有一个输入字段,如下所示:
<logic:iterate name="listOfQuestions" id="listOfQuestionsId" indexId="indexId">
<tr>
<td align="right" width="100%"><bean:message key='<%= "prompt.question" + (indexId.intValue() +1)%>'/>: </td><td width="100%" nowrap="nowrap"><bean:write name="listOfQuestionsId"/></td>
</tr>
<tr align="center">
<td align="right" width="50%"><bean:message key="prompt.answer"/>: </td>
<td align="left" width="50%"><html:password property="questions" size="30" maxlength="40" indexed="true"></html:password></td>
</tr>
</logic:iterate>
问题和答案字段显示良好。
我唯一的问题是,试图访问操作类中所有输入字段的值。
这是我的表格:
多个问题表单
public class MultipleQuestionsForm extends ActionForm {
private List<String> questions=null;
/**
* @return the questions
*/
public List<String> getQuestions() {
return questions;
}
/**
* @param questions the questions to set
*/
public void setQuestions(List<String> questions) {
this.questions = questions;
}
//omitted the rest (Validate, constructor, reset method)
}
这是我的一部分
ActionClass
:
getQuestions()返回null
//Use the ValidateInfoForm to get the request parameters
MultipleQuestionsForm validateQuestionsForm = (MultipleQuestionsForm) form;
List<String> listOfquestions = validateQuestionsForm.getQuestions();
for(String s: listOfquestions) System.out.println(s); //nullPointer since getQuestions() doesn't return the input values