2014-02-19 3 views
2

Любая помощь будет принята с благодарностью: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)%>'/>:&nbsp;&nbsp;</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"/>:&nbsp;&nbsp;</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 

ответ

2

Как вы ожидаете ваши вопросы свойство должно отображать как List<String> questions fr om ваш jsp/view? Вы пробовали отлаживать свой validateQuestionsForm? если да, пожалуйста, проверьте свой вопрос. Все, что вам нужно сделать, это изменить ваше свойство списка на String array. Как это в вашем MultipleQuestionsForm,

private String[] questions; 

И геттер для этой недвижимости. Теперь вы можете получить массив строк и повторить его. Надеюсь это поможет.

+0

Да, я отметил это. Рад, что вы его получили сами. Ура .. –

Смежные вопросы