In my Spring MVC application I need to implement a dynamic questionnaire form: I have N questions and for each I have 3 options.
So in my page I\'ll have something like
This class is my model attribute:
public class Questionnaire {
private List questions = new ArrayList<>();
private List answers = new ArrayList<>();
// set + get
}
And:
public class Question {
private int id;
private String text;
// set+ get
}
public class Answer {
private int questionId;
private int value;
// set + get
}
I populate questions
list before I put it into model.
In my page I use this code:
${question.text}
Posting this form I get a fully populated questionnaire
instance in my controller.
NOTE I found this post very helpful to solve my problem.