Любая помощь будет принята с благодарностью:Struts 1,3 перебирать динамический список вопросов
В моем 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>
поля вопросов и ответов отображаются в порядке.
Моя единственная проблема, пытается получить доступ к значению всех полей ввода в моем классе действий.
Вот моя форма: MultipleQuestionsForm
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() возвращает нуль
//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
Да, я отметил это. Рад, что вы его получили сами. Ура .. –