Your SlideShare is downloading. ×
0
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Annotation-Based Spring Portlet MVC

14,674

Published on

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 …

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

Published in: Technology, Education
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
14,674
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
387
Comments
0
Likes
4
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Annotation-Based Spring Portlet MVC John A. Lewis Chief Software Architect Unicon, Inc. Jasig 2010 Conference 8 March 2010 © Copyright Unicon, Inc., 2010. Some rights reserved. This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/us/
  • 2. Spring MVC <ul><li>Flexible and Lightweight
  • 3. Request-Oriented Web Framework
  • 4. Implements Classic MVC Pattern </li><ul><li>Model </li><ul><li>Information to be presented
  • 5. Contract between Controller and View </li></ul><li>View </li><ul><li>User interface definition
  • 6. Used to render the Model for display </li></ul><li>Controller </li><ul><li>Handles the request and assembles the Model
  • 7. Delegates to service layer for business logic </li></ul></ul></ul>
  • 8. Dispatcher (Servlet/Portlet) Request Handler Mapping View Resolver Response Controller View ModelAndView Map (Model) viewName
  • 9. Sample Portlet Application <ul><li>Things we need to do: </li><ul><li>Get development environment installed
  • 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 </li></ul></ul>http://localhost:8080/pluto/portal <ul><ul><li>Explore the web.xml and portlet.xml files </li></ul></ul>
  • 15. Annotation-Based Controllers Where to put the logic
  • 16. Annotation-Based Controllers <ul><li>New in Spring Framework 2.5!
  • 17. Eliminates need for complex HandlerMapping 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 entire Controller hierarchy – most capability already supported </li></ul>
  • 20. Annotation-Based Controller Beans <context:annotation-config/> <bean class=&quot;org.springframework.web.portlet.mvc. annotation.DefaultAnnotationHandlerMapping&quot;/> <bean class=&quot;org.sample.MyViewController&quot;/> <bean class=&quot;org.sample.MyEditController&quot;/> <bean class=&quot;org.sample.MyHelpController&quot;/>
  • 21. Spring MVC Controller Annotations <ul><li>@Controller – class stereotype for controller classes so they can be found and mapped
  • 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 </li></ul>
  • 27. Annotation-Based Controller Examples @Controller @RequestMapping(&quot;VIEW&quot;) @SessionAttributes(&quot;item&quot;) public class MyViewController { @RequestMapping public String listItems(Model model) { model.addAttribute(&quot;items&quot;, this.itemService.getAllItems()); return &quot;itemList&quot;; } @RequestMapping(params=&quot;action=view&quot;) public String viewPet( @RequestParam(&quot;item&quot;) int itemId, Model model) { model.addAttribute(&quot;item&quot;, this.itemService.getItem(itemId)); return &quot;itemDetails&quot;; } ...
  • 28. Annotation-Based Controller Examples ... @ModelAttribute(&quot;dateFormat&quot;) protected String dateFormat(PortletPreferences prefs) { return preferences.getValue(&quot;dateFormat&quot;, itemService.DEFAULT_DATE_FORMAT); } @InitBinder public void initBinder(PortletRequestDataBinder binder, PortletPreferences preferences) { String format = preferences.getValue(&quot;dateFormat&quot;, ItemService.DEFAULT_DATE_FORMAT); SimpleDateFormat dateFormat = new SimpleDateFormat(formatString); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); } ...
  • 29. Annotation-Based Controller Sample <ul><li>src/main/java/ </li><ul><li>sample/portlet/MyBooksController.java
  • 30. sample/portlet/BooksController.java </li></ul></ul>
  • 31. Portlet 2.0 (JSR 286) Support The next generation portlet framework
  • 32. Major Changes in Portlet 2.0 <ul><li>Portlet Events (New lifecycle phase!)
  • 33. Resource Serving (New lifecycle phase!)
  • 34. Public Render Parameters
  • 35. Portlet Filters
  • 36. Caching Changes </li></ul>Lots of other minor changes...
  • 37. Portlet 2.0 In Spring 3.0 <ul><li>Support for new features of Portlet 2.0 included as part of Spring 3.0
  • 38. Spring 3.0 released 16 Dec 2009
  • 39. Primary need is support for four phases: </li><ul><li>ActionRequest / ActionResponse
  • 40. EventRequest / EventResponse (new!)
  • 41. RenderRequest / RenderResponse
  • 42. ResourceRequest / ResourceResponse (new!) </li></ul></ul>
  • 43. Annotations for Portlet 2.0 Support <ul><li>@ActionMapping </li></ul>Elements: name, params <ul><li>@EventMapping </li></ul>Elements: name, qname, params <ul><li>@RenderMapping </li></ul>Elements: windowState, params <ul><li>@ResourceMapping </li></ul>Elements: id, params
  • 44. Portlet 2.0 Examples @ActionMapping(”delete”) public void deleteItem(...) { ... } @EventMapping(”reload”) public void reloadData(...) { ... } @RenderMapping(&quot;maximized&quot;, params=&quot;action=search&quot;) public String displaySearch(...) { ... } @ResourceMapping(”picklist”) public ModelAndView pickList (...) {...}
  • 45. Questions & Answers John A. Lewis Chief Software Architect Unicon, Inc. [email_address] www.unicon.net

×