I have this link on my test.jsp page
<a onclick="treeViewAjax('${searchDummyUrl}/view/${search.DummyNumber}/1')">View</a>
Now when I click on this then treeViewAjax ,A JavaScript method is being invoked as you can see in the link
Here is the treeViewAjax method
function treeViewAjax(Url){
$.ajax(Url, function(data) {
alert(data);
});
}
and at the same time my Spring controller's searchDummyView method invoked
@RequestMapping(value = "/Dummy/searchDummy/view/{dummyNumber}/{dummyTypeId}", method = RequestMethod.POST)
public @ResponseBody
List<Report> searchDummyView(ModelMap modelMap, @PathVariable("dummyNumber") Integer dummyNumber, @PathVariable("dummyTypeId") Integer dummyTypeId) {
List<Report> reportList = new ArrayList<>();
reportList.add(dummyService.readReport(dummyNumber, dummyTypeId));
//modelMap.addAttribute("reportList", reportList);
return reportList;
}
Now when as Spring expert's can understand that I have used @ResponseBody annotation as to make to ajaxical request So it then again send response back to the requested URL.Now here again control is on my JS method treeViewAjax and when I alert the data then it show the list values perfectly.
Now I am stuck here that
How can I capture reportList returned by searchDummyView method on JSP page as well as How to iterate/Show its value on the JSP page using EL.
Any suggestions?
Note: I have tried to show reportList like this but it didn't work for me
<c:choose>
<c:when test="${reportList.size() > 0}">
<c:forEach items="${reportList}" var="list">
//iterations over list but
</c:forEach>
...
... />
It did't display anything from list because of my condition < 0 and I guess it is returning 0 size here OR not accessible here.(could be any reason)
//modelMap.addAttribute("reportList", reportList);this , the AJAX response is read in JS and there are noreportListin any of the scope.@ResponseBodydue to apply ajax thing and in this case we always return the data neither add it to in modelmap