If you can't read please download the document
Upload
john-lewis
View
14.590
Download
5
Embed Size (px)
DESCRIPTION
Starting with Spring MVC 2.5, Annotation-Based Controllers became the preferred model for development (the Interface-based Controller hierarchy will be deprecated in Spring 3). This session will teach developers familiar with the old model how to use the new Annotation-based Controllers. This will also provide the basis for writing JSR 286 portlets using Spring 3. Sample code available here: http://www.ja-sig.org/wiki/x/vYS8AQ Full screencast available here: http://vimeo.com/10020881
Citation preview
2. Spring MVC
3. Request-Oriented Web Framework 4. Implements Classic MVC Pattern
5. Contract between Controller and View View
6. Used to render the Model for display Controller
7. Delegates to service layer for business logic 8. Dispatcher (Servlet/Portlet) Request Handler Mapping View Resolver Response Controller View ModelAndView Map (Model) viewName 9. Sample Portlet Application
10. Setup Pluto as a Server in Eclipse & start it 11. Import 'spring-portlet-sample' application 12. Create Maven task to build & deploy 13. Build & deploy the sample application 14. Verify that it works in Pluto http://localhost:8080/pluto/portal
15. Annotation-Based Controllers Where to put the logic 16. Annotation-Based Controllers
17. Eliminates need for complexHandlerMapping configuration to deal with navigation via Portlet Modes and Request Parameters 18. Allows related logic to be combined into a single Controller class 19. Will replace the entireControllerhierarchy most capability already supported 20. Annotation-Based Controller Beans 21. Spring MVC Controller Annotations
22. @SessionAttributes list model attributes to be stored in the session (command object) 23. @RequestMapping class/method mapping to requests (mode, parameters, etc.) 24. @RequestParam bind method params to request params 25. @ModelAttribute bind method params or return values to model attributes 26. @InitBinder method to setup binder for putting form submission into command obj 27. Annotation-Based Controller Examples @Controller @RequestMapping("VIEW") @SessionAttributes("item") public classMyViewController{ @RequestMapping public String listItems(Model model) { model.addAttribute("items",this.itemService.getAllItems()); return "itemList"; } @RequestMapping(params="action=view") public String viewPet( @RequestParam("item")int itemId, Model model) { model.addAttribute("item", this.itemService.getItem(itemId)); return "itemDetails"; } ... 28. Annotation-Based Controller Examples ... @ModelAttribute("dateFormat") protected String dateFormat(PortletPreferences prefs) { return preferences.getValue("dateFormat",itemService.DEFAULT_DATE_FORMAT); } @InitBinder public void initBinder(PortletRequestDataBinder binder, PortletPreferences preferences) { String format = preferences.getValue("dateFormat", ItemService.DEFAULT_DATE_FORMAT); SimpleDateFormat dateFormat =new SimpleDateFormat(formatString); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); } ... 29. Annotation-Based Controller Sample
30. sample/portlet/BooksController.java 31. Portlet 2.0 (JSR 286) Support The next generation portlet framework 32. Major Changes in Portlet 2.0
33. Resource Serving(New lifecycle phase!) 34. Public Render Parameters 35. Portlet Filters 36. Caching Changes Lots of other minor changes... 37. Portlet 2.0 In Spring 3.0
38. Spring 3.0 released 16 Dec 2009 39. Primary need is support for four phases:
40. EventRequest / EventResponse(new!) 41. RenderRequest / RenderResponse 42. ResourceRequest / ResourceResponse(new!) 43. Annotations for Portlet 2.0 Support
Elements: name, params
Elements: name, qname, params
Elements: windowState, params
Elements: id, params 44. Portlet 2.0 Examples @ActionMapping(delete) public void deleteItem(...) { ... } @EventMapping(reload) public void reloadData(...) { ... } @RenderMapping("maximized", params="action=search") public String displaySearch(...) { ... } @ResourceMapping(picklist) public ModelAndView pickList (...) {...} 45. Questions & Answers John A. Lewis Chief Software Architect Unicon, Inc. [email_address] www.unicon.net