i'm looking into using Spring MVC - how would I structure the fact that a page can be composed of several different views
Consider a controller that's basically:
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
List<Post> posts = repository.getNewPosts();
return new ModelAndView("posts", "posts", posts);
}
However, I decide that on every page, I'd also want a side "pane" that shows data based on some logic. That "pane" would just be a .jsp that gets included from the above "posts" view, and I could change my controller to:
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
List<Post> posts = repository.getNewPosts();
List<Items> items= repository.getItems();
return new ModelAndView("model", "model", new MyCommonViewModel(posts,items));
}
But then I'd have to change every controller to also do List<Items> items= repository.getItems(); , and change everything again the next time I come up with something new.
This seems messy. How do I structure this ?
`