「ネストされた」質問を実際に必要なときにロードするには、ajaxを使用できます。たとえば、Spring MVCコントローラーでは、次のようなメソッドを実装できます。
@RequestMapping("/nestedQuestions")
public @ResponseBody List<Question> getNestedQuestions(@RequestParam("parentQuestion") int id){
return yourService.getChildrenQuestionsFor(id);
}
Question
単純なオブジェクトである可能性があります。
public class Question {
private int id;
private String text;
// ...
}
次に、ページで、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);
}
});
}
この関数は、親の質問IDを渡して、ラジオボタンイベントハンドラーgetNestedQuestions
から呼び出すことができます。onChange