Reputation: 3737
I'm loading a jsp page and in the controller I add a List as model attribute. then the list is displayed as follows in the jsp page.
<c:forEach var="pattern" items="${patterns}">
<li class="list-group-item liitem"><strong>${pattern.id}:</strong>
<span class="pull-right">${pattern.name}</span>
</li>
</c:forEach>
Here is the controller that i call
@RequestMapping(method = RequestMethod.GET)
public ModelAndView printWelcome(ModelMap model){
ModelAndView mav = new ModelAndView("arcane") ;
List<Pattern> patternList=patternDao.patternList();
mav.addObject("patterns", patternList);
return mav;
}
But patternList
gets changed time to time as this is fetched from a database. How can I update those changes without loading whole jsp page. All I want is how can i update only one div tag by calling the controller again?
I tried to use ajax to call controller method,but how can I apply new list to jsp view using ajax.
Upvotes: 0
Views: 48
Reputation: 37
You can give an id to that div and when you want to refresh the list make an ajax call to the controller in the response find that div, and replace the content if the div in your page with the one in the response, (by setting the InnerHtml of the div)
Or
You could create a jsp page containing only the list, (the foreach tag)
create a new controller method
@RequestMapping(value = "justTheList" method = RequestMethod.GET)
public ModelAndView printWelcome(ModelMap model){
ModelAndView mav = new ModelAndView("JSPPAGE_WITH_THE_LIST") ;
List<Pattern> patternList=patternDao.patternList();
mav.addObject("patterns", patternList);
return mav;
}
set the InnerHtml of the or to the response ;
Upvotes: 1
Reputation: 398
Use Ajax, and when you get the response change the content.
Check this: http://jsfiddle.net/Lobmx96y/1/
Upvotes: 1