Lets assume your application looks like this:

public class QuestionAndAnswers {
   private Question question;
   private List<Answer> possibleAnswers;
}

public class AnsweredQuestion {
   private Question question;
   private Answer answer;
}

public interface WebService {
   public List<QuestionAndAnswers> getQuiz(String quizId);
}

I think I'd do it like this

public class Page {
   @Inject
   private WebService webService;

   @Property
   private List<AnsweredQuestion> answeredQuestions;

   @Property
   private AnsweredQuestion current;

   private Map<Question, List&lt;Answer>> answerMap;

   public SelectModel getSelectModel() {
      List<Answer> possibleAnswers = answerMap.get(current);
      return createSelectModel(possibleAnswers);
   }

   public ValueEncoder<AnsweredQuestion> getEncoder() {
      // this will be used to serialize/deserialize each value to a hidden
value in the form
   }

   public void onPrepareRender() {
      List<QuestionAndAnswers> qsAndAs = webService.getQuiz(String quizId);
      // initialize answeredQuestions
      // initialize answerMap
   }
}

tml
<t:loop source="answeredQuestions" value="current" encoder="encoder">
   ${current.question.question}
   <t:select value="current.answer" model="selectModel" />
</t:loop>

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Help-with-Dynamic-Number-of-Form-Elements-tp5681909p5682584.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to