Annotation-Based Spring Portlet MVC John A. Lewis Chief Software Architect Unicon, Inc. Jasig 2010 Conference 8 March 2010...
Spring MVC <ul><li>Flexible and Lightweight
Request-Oriented Web Framework
Implements Classic MVC Pattern </li><ul><li>Model </li><ul><li>Information to be presented
Contract between Controller and View </li></ul><li>View </li><ul><li>User interface definition
Used to render the Model for display </li></ul><li>Controller </li><ul><li>Handles the request and assembles the Model
Delegates to service layer for business logic </li></ul></ul></ul>
Dispatcher (Servlet/Portlet) Request Handler Mapping View Resolver Response Controller View ModelAndView Map (Model) viewN...
Sample Portlet Application <ul><li>Things we need to do: </li><ul><li>Get development environment installed
Setup Pluto as a Server in Eclipse & start it
Import 'spring-portlet-sample' application
Create Maven task to build & deploy
Build & deploy the sample application
Verify that it works in Pluto </li></ul></ul>http://localhost:8080/pluto/portal <ul><ul><li>Explore the  web.xml  and  por...
Annotation-Based Controllers Where to put the logic
Annotation-Based Controllers <ul><li>New in Spring Framework 2.5!
Eliminates need for complex  HandlerMapping   configuration to deal with navigation via Portlet Modes and Request Parameters
Upcoming SlideShare
Loading in...5
×

Annotation-Based Spring Portlet MVC

14,768

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 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,768
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
387
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Annotation-Based Spring Portlet MVC

  1. 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. 2. Spring MVC <ul><li>Flexible and Lightweight
  3. 3. Request-Oriented Web Framework
  4. 4. Implements Classic MVC Pattern </li><ul><li>Model </li><ul><li>Information to be presented
  5. 5. Contract between Controller and View </li></ul><li>View </li><ul><li>User interface definition
  6. 6. Used to render the Model for display </li></ul><li>Controller </li><ul><li>Handles the request and assembles the Model
  7. 7. Delegates to service layer for business logic </li></ul></ul></ul>
  8. 8. Dispatcher (Servlet/Portlet) Request Handler Mapping View Resolver Response Controller View ModelAndView Map (Model) viewName
  9. 9. Sample Portlet Application <ul><li>Things we need to do: </li><ul><li>Get development environment installed
  10. 10. Setup Pluto as a Server in Eclipse & start it
  11. 11. Import 'spring-portlet-sample' application
  12. 12. Create Maven task to build & deploy
  13. 13. Build & deploy the sample application
  14. 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. 15. Annotation-Based Controllers Where to put the logic
  16. 16. Annotation-Based Controllers <ul><li>New in Spring Framework 2.5!
  17. 17. Eliminates need for complex HandlerMapping configuration to deal with navigation via Portlet Modes and Request Parameters
  18. 18. Allows related logic to be combined into a single Controller class
  19. 19. Will replace the entire Controller hierarchy – most capability already supported </li></ul>
  20. 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. 21. Spring MVC Controller Annotations <ul><li>@Controller – class stereotype for controller classes so they can be found and mapped
  22. 22. @SessionAttributes – list model attributes to be stored in the session (command object)
  23. 23. @RequestMapping – class/method mapping to requests (mode, parameters, etc.)
  24. 24. @RequestParam – bind method params to request params
  25. 25. @ModelAttribute – bind method params or return values to model attributes
  26. 26. @InitBinder – method to setup binder for putting form submission into command obj </li></ul>
  27. 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. 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. 29. Annotation-Based Controller Sample <ul><li>src/main/java/ </li><ul><li>sample/portlet/MyBooksController.java
  30. 30. sample/portlet/BooksController.java </li></ul></ul>
  31. 31. Portlet 2.0 (JSR 286) Support The next generation portlet framework
  32. 32. Major Changes in Portlet 2.0 <ul><li>Portlet Events (New lifecycle phase!)
  33. 33. Resource Serving (New lifecycle phase!)
  34. 34. Public Render Parameters
  35. 35. Portlet Filters
  36. 36. Caching Changes </li></ul>Lots of other minor changes...
  37. 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. 38. Spring 3.0 released 16 Dec 2009
  39. 39. Primary need is support for four phases: </li><ul><li>ActionRequest / ActionResponse
  40. 40. EventRequest / EventResponse (new!)
  41. 41. RenderRequest / RenderResponse
  42. 42. ResourceRequest / ResourceResponse (new!) </li></ul></ul>
  43. 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. 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. 45. Questions & Answers John A. Lewis Chief Software Architect Unicon, Inc. [email_address] www.unicon.net
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×