Hallo everybody,
I registered that many people are looking for controller chaining or some kind of hmvc (hierarchical model view controllers) following this simple diagram:
Code:View(Model1,2,3) <-> Controller 1(Model1) <-> Controller 2(Model 2) <-> Controller 3 (Model 3)
As seen at java.com
In this case you do not need to implement someting special in spring, you can just chain controllers and their execution if you define a following kind of controller within the parent and merge resulting model data:
Code:public class Page { /** Build hierarchical page flow by refererencing to other pages */ private HashMap<String, Page> subPages = new HashMap<String, Page>(); /** * This is our page specific controller */ private Controller controller; public Controller getController() { return controller; } public void setController(Controller controller) { this.controller = controller; } /** Here is our hierarchy !! */ public HashMap<String, Page> getSubPages() { return subPages; } public void setSubPages(HashMap<String, Page> subPages) { this.subPages = subPages; } public Page() { } }
Now you can simply define a ModelAndView Chain in the top page and any subsequent page by simply coding a model merger:
Code:public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, Exception { ... Map model = new HashMap(); model.put("selectedTopPage", selectedTopPage); model.put("selectedSubPage", selectedSubPage); model.put("selectedTopPageName", selectedTopPageName); model.put("selectedSubPageName", selectedSubPageName); ... /** THE FOLLOWING LINES ARE FOR CHAINING AND MERGING */ /** BOTH MODELS ARE MERGED, YOU COULD EVEN PUSH THE RESULTING VIEW FROM SUB PAGES*/ if (selectedSubPage.getController() != null){ model.putAll( selectedSubPage.getController().handleRequest(request, response).getModel()); } return new ModelAndView(pageLayout.getView(), "model", model); }
This works very perfect for me and should be applicable to most web applications page layout and navigation patterns with subsequent page structures and differnt controllers for each subpage. Please sorry me about not posting the whole code here, but it is not hard to implement. This approach even subsitutes the need for components or struts tiles)
More detailed information about hmvc can be found here: http://www.javaworld.com/javaworld/j...21-hmvc_p.html
(MVC layers from Javaworld.com)
Just contact me when you need more information about it, I appreciate any direct questions within this forum or as openbc question.
Andreas Bednarz, Germany - Hannover
Senior J2EE Developer
https://www.openbc.com/hp/Andreas_Bednarz/



)
Reply With Quote

