I have 2 java classes. One is a java bean and the other is a collection of instances from this java bean class.
public class Quiz{
private int id;
private String title;
//getters and setters
}
public class Quizzes{
List<Quiz> quizList = new ArrayList<Quiz>;
public Quizzes{
//constructor to add Quiz objects to quizList
Quiz curQuiz = new Quiz();
...
}
public List<Quiz> getQuizList(){
return this.quizList;
}
}
In my JSP I want to access for example the id (or title) of a Quiz. How can I do this? The only Idea I have is to iterate over the Objects in quizlist and call getId Method, and then add this Integer Values to a List. For example like this:
public List<Integer> getId(){
List<Integer> idList = new ArrayList<Integer>();
ListIterator<Quiz> ir = quizlist.listIterator();
int id;
while (ir.hasNext()){
Quiz curQuiz = ir.next();
id = curQuiz.getId();
idList.add(id);
}
return idList;
}
But isn't there a better solution?