Component Controller in Spring-MVC

I am developing a web application that requires multiple components to be loaded on one page. (Similar to a Google reader in terms of page layout) I like to keep these components separate from each other (for reasons such as reuse). For example, I have a left pane that allows the user to navigate between several channels they have subscribed to (depending on the user), and on the right side of it we show the content of that feed, and perhaps a right pane that shows some specific information. about this specific feed. My understanding of MVC and more specifically Spring-MVC is that each controller is responsible for the entire page. Here are two solutions I came up with after researching this a bit and none of them fit me.

  • Have a main controller that maps to this url and then load other components from the jsp file. It's doable, but doesn't seem like a good solution.
  • Using portlets.

I want to know what are the best practices. This seems like a very common web design problem in MVC frameworks, how do people do it?

+2


source to share


1 answer


Spring MVC Controller usually "responds" :-) to process a specific request , which does not necessarily mean that the specified request results in the page being rendered as a monolithic page.

Since you are talking about features like Google Reader, perhaps you will be using AJAX to load / navigate between different components on your page? If so, you can easily map your 3 components to separate controllers (via separate URIs) and have one "master" controller for the initial load of the entire page.



If this is not the case and your page is static, you can force your controller to act as a sorting "router" by first instantiating your components and then dispatching commands / requests to the appropriate component as needed. Each component would update its part of the model, after which your "main" controller would return the view to be displayed.

Can you use portlets for this? Sure. But if we are talking about one page, it may be a little overkill.

+1


source







All Articles