I have an entity, with a field containing a list to Refs to other entities (always 4). I'm trying to get some entities, and dispatch them for a jsp for display. I want all the Refs in the field to be loaded as well, and to access them in the jsp.
Here is my basic structure:
@Entity
public class Question {
@Id Long id;
@Index String question;
@Load List<Ref<Answer>> answers = new ArrayList<Ref<Answer>>();
}
When I'm fetching question like this, obviously there's an error in the jsp. Makes sense, because answers field is not a list of answers, but of refs:
ObjectifyService.register(Question.class);
ObjectifyService.register(Answer.class);
List<Question> questions = ofy().load().type(Question.class).limit(50).list();
req.setAttribute("questions", questions);
try {
getServletContext().getRequestDispatcher("/admin/view-questions.jsp").forward(req, resp);
} catch (ServletException e) {
System.out.println (e.getMessage());
}
So how do access the answers in the jsp? is the only way to manually loop through the questions and do a get() for the answers field?
Answer (myQuestion.getAnswers().add(newAnswer);
) I get anexception: java.lang.UnsupportedOperationException at java.util.AbstractList.add(Unknown Source)
– Ulster