Reputation: 149
I have a list which has a another list defined in it.So,assume them as a reflection objects.(List inside a list inside a list ...so on). In my view I start with one YES/NO question and based on YES, I have to display a collection of data. Again when a user checks YES display the set.
I can achieve this by constructing the question and hiding them before presenting to the client and when user checks YES,I enable that set.But the collection which I am working is huge,so I don't want to render the collection and hide if that is of no use. I would like to know if there is a better way to achieve this.(Spring MVC 3, Java 6)
Thanks
Upvotes: 0
Views: 249
Reputation: 24686
To load "nested" questions just when you actually need it you could use ajax. For example, in your Spring MVC controller you could implement a method like this:
@RequestMapping("/nestedQuestions")
public @ResponseBody List<Question> getNestedQuestions(@RequestParam("parentQuestion") int id){
return yourService.getChildrenQuestionsFor(id);
}
Question
could be a simple object:
public class Question {
private int id;
private String text;
// ...
}
Then in your page, if you are using jQuery:
function getNestedQuestions(parentQuestionId) {
$.ajax({
type : "GET",
url : '/nestedQuestions',
data : {
parentQuestion : parentQuestionId
},
success : function(data) {
// for each question in data, show it...
},
error : function(jqXHR, textStatus, errorThrown) {
alert(jqXHR.responseText);
}
});
}
The getNestedQuestions
function can be called from your radiobutton onChange
event handler, passing the parent question id.
Upvotes: 1