developing portlets
TRANSCRIPT
![Page 1: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/1.jpg)
Developing Portlets With the Spring MVC Framework
Presented by: Michael SlavenTeachers College, Columbia University
March 21st, 2011Session ID 4271
![Page 2: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/2.jpg)
Session Rules of Etiquette
• Please turn off your cell phone/pager
• If you must leave the session early, be sure not to knock over anyone’s coffee.
• If you must yawn or snore, please do so as discreetly as possible.
Session ID 4271 2
![Page 3: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/3.jpg)
Agenda
• Some examples of portlets built using the Spring MVC framework
• Why develop portlets?• Why use Spring MVC?
• An overview of portlets and the JSR portlet specs— request phases —portlet modes —window states —URL handling
• An overview of Spring MVC—model, view, controller
Session ID 4271 3
![Page 4: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/4.jpg)
Agenda - continued
• Putting it all together
—Setting up a dev environment and directory structure
—Configuring Spring and annotations
—Creating the ViewController
—Creating the DirectoryService
—Create the JSP views “search” and “searchresults”
—Deployment
Session ID 4271 4
![Page 5: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/5.jpg)
About Teachers College
• The oldest and largest graduate
school of education in the U.S.
• Affiliated with Columbia
University
• Located in the northern end of
Manhattan
• ~5400 students
• ~1000 staff
• 165 full time faculty
Session ID 4271 5
![Page 6: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/6.jpg)
Some examples of portlets built using the Spring MVC framework
![Page 7: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/7.jpg)
The myTC Message Center
Our most recent (and biggest) Spring MVC portlet
Session ID 4271 7
![Page 8: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/8.jpg)
Session ID 4271 8
![Page 9: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/9.jpg)
Session ID 4271 9
![Page 10: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/10.jpg)
Features of the myTC Message Center
• Uses Spring 2.5
• Hibernate for data persistence
• Sends emails instantly and generates daily digest emails for each user
• Emails use Apache Velocity templating engine
Session ID 4271 10
![Page 11: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/11.jpg)
The myTC Photo Directory
Our first (and smallest) Spring MVC portlet
“More Options” allows search bytitle, office, phone, email, role(staff, student or faculty)
Session ID 4271 11
![Page 12: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/12.jpg)
Session ID 4271 12
Why portlets?Why Spring MVC?
![Page 13: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/13.jpg)
Why develop portlets?
• Make your code portable across portal products.— The JSR-168 portlet API is supported by all major
portal products
• Easily re-use code by having multiple instances.
• If you want to do custom development in Luminis 5, you have to.
(Lum 5 doesn’t support channels)
Session ID 4271 13
![Page 14: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/14.jpg)
Why use the Spring MVC framework?
• It separates presentation from business logic.
• It uses dependency injection for simplification and to increase testability.
• It lets you focus on functionality instead of infrastructure.
• Spring's view resolution is very flexible.—Out of the box, Spring enables you to use JSPs, Velocity
templates and XSLT views, among others.
Session ID 4271 14
![Page 15: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/15.jpg)
An overview of the JSR portlet specs
![Page 16: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/16.jpg)
JSR 168 and JSR 286 Portlet Specs
• JSR 168 aka Portlet 1.0 specification
— released Oct 2003
— supported by Luminis 4.2 and Lum 5
• JSR 286 aka Portlet 2.0 specification
— released Jun 2008
—supported by Luminis 5
Session ID 4271 16
![Page 17: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/17.jpg)
Request Phases
• Action requests—can be used to change system state—executed only once—produces no markup
• Render requests—Cannot change system state—executed at least once—produces markup
• Event requests (Portlet 2.0 only)• Resource requests (Portlet 2.0 only)
Session ID 4271 17
![Page 18: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/18.jpg)
Request Handling Sequence (from JSR 286 spec)
Session ID 4271 18
![Page 19: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/19.jpg)
Portlet Modes
• Modes specify the current function of the portlet. • There are three standard portlet modes:
—VIEW: normal mode—EDIT: edit mode, for portlet specific preferences—HELP: help mode, for portlet specific help
• All 3 are not necessary. Some portlets have only a VIEW mode.
• Portlets can have other custom-defined modes as well.
• These can be changed by the user, usually with an icon in the portlet’s toolbar, or they can be changed programmatically.
Session ID 4271 19
![Page 20: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/20.jpg)
Window States
• Window States specify the size or amount of detail.
• There are three standard windows states:—NORMAL: normal window state —MAXIMIZED: largest window, usually fills the portal
window—MINIMIZED: smallest window, usually only a toolbar
remains
• These can be changed by the user, usually with an icon in the portlet’s toolbar, or they can be changed programmatically.
Session ID 4271 20
![Page 21: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/21.jpg)
URL Handling
• There is no portlet URL you can link to, since the portal controls the actual URL.
• Use the API for generating URLs and setting URL parameters (PortletURL Objects).
• Use a combination of Portlet Mode, Window State, and Request Parameters for navigation.
Session ID 4271 21
![Page 22: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/22.jpg)
An overview of the Spring MVC framework
![Page 23: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/23.jpg)
What is Spring MVC?• Spring is a flexible and lightweight application
framework that utilizes dependency injection.• MVC is a common design pattern that isolates the
data (model) and domain logic (controller) from the user interface (view).
Session ID 4271 23
![Page 24: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/24.jpg)
Model – The M in MVC
• The model encapsulates the data and application state.
• It responds to requests for information about its state (usually coming from the view).
• It responds to instructions to change state (usually coming from the controller).
Session ID 4271 24
![Page 25: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/25.jpg)
Views – The V in MVC
• The view displays the user interface and renders the model for display.
• It also sends user actions to the controller.
• JSP & JSTL are the most common view technologies, but XSLT, Velocity, PDF Docs, etc. are all supported.
• In portlets you generally only use view technology that produces HTML markup.
• Multiple views can exist for a single model for different purposes.
Session ID 4271 25
![Page 26: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/26.jpg)
Controllers – The C in MVC
• A controller processes user input from a view and initiates a response by making changes to the model.
• It selects the view to use for the response.
• It often delegates to the service layer for the business logic.
• There are often multiple controllers.
Session ID 4271 26
![Page 27: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/27.jpg)
Putting it all together
![Page 28: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/28.jpg)
Photo Directory “Lite”
• Our example is a person search that returns a thumbnail image of a person as well as their contact info and office hours (if applicable).
• Has 2 views:—SEARCH: a form to enter first name, last name, etc—SEARCHRESULTS: the results, paginated 5 at a time
• Has a single domain object:—DirectoryEntry: setters and getters for a single entry in the
photo directory
• Has a single controller
• Has a single DB service object
Session ID 4271 28
![Page 29: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/29.jpg)
Notes on setting up a dev environment
• Install the JDK and set JAVA_HOME—JRE is not enough
• Install an IDE—Eclipse—NetBeans—Use Maven to simplify dependencies, building, and
deploying
• Install a portal / portlet container—uPortal 2.5.6 is best if developing for Lum 4—Liferay 5.2.x is best if developing for Lum 5—Or you can use Pluto from Apache
Session ID 4271 29
![Page 30: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/30.jpg)
Set up the directory structure
• /WEB-INF -- all protected resources
• Individual class files should be stored in a directory structure within /WEB-INF/classes that reflects the class package.
• /WEB-INF/jsp – jsp views
• /WEB-INF/lib – referenced JAR files
Session ID 4271 30
![Page 31: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/31.jpg)
Include the Spring libraries
Session ID 4271 31
• Use Maven to handle your dependencies. • This is done using the “Project Object Model” pom.xml file at
the root of your project.• Maven then downloads all necessary libraries and places them
in WEB-INF/lib.
![Page 32: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/32.jpg)
Configure portlet.xml
• The Spring DispatcherPortlet dispatches requests to your controllers.
• This will be the same for any Spring portlet.
Session ID 4271 32
![Page 33: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/33.jpg)
Configure web.xml
• Spring portlets are an extension of spring servlets.• DispatcherPortlet uses ViewRendererServlet to
dispatch view rendering into a servlet context.• Also, load the parent ApplicationContext using
ContextLoaderListener.
Session ID 4271 33
![Page 34: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/34.jpg)
Configure PhotoDirectory-portlet.xml -- Annotations --
• Setup DefaultAnnotationHandlerMapping.
• Tell Spring where to scan for annotations like @Controller, @RequestMapping, @Autowired etc.
Session ID 4271 34
![Page 35: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/35.jpg)
Configure PhotoDirectory-portlet.xml -- View Resolver --
• Using JstlView we don’t have to build views ourselves.• Refer to a view by name, and the jsp file of that name
becomes the view.• The prefix and suffix are added, so that the view “search”
becomes /WEB-INF/jsp/search.jsp
Session ID 4271 35
![Page 36: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/36.jpg)
Controller & Handler Mapping
• With Spring 2.5+ we can simplify by using annotations.
• Without annotations:—The controller needs to extend a base controller
like AbstractController. —Handler beans have to be defined in the application
context.
• With annotations:—Annotate the controller class with “@Controller”.—Annotate handlers with
“@RequestMapping([params])”.
Session ID 4271 36
![Page 37: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/37.jpg)
ViewController
Session ID 4271 37
![Page 38: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/38.jpg)
ViewController - Continued
Session ID 4271 38
![Page 39: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/39.jpg)
DirectoryServiceImpl.java
Session ID 4271 39
![Page 40: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/40.jpg)
DirectoryServiceImpl.java - Continued
Session ID 4271 4040
![Page 41: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/41.jpg)
DirectoryServiceImpl.java - Continued
Session ID 4271 41
![Page 42: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/42.jpg)
VIEW: search.jsp
Session ID 4271 42
![Page 43: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/43.jpg)
VIEW: searchresults.jsp
Session ID 4271 43
![Page 44: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/44.jpg)
Deploy!
• Use Maven or Ant to package your portlet into a deployable war file.
• On Lum 4—Run cptool deploy portlet /path/to/PhotoDirectory.war—A restart is required.
• On Lum 5 and Liferay—Simply copy the war file to your hot deploy directory, or
upload using the Admin GUI.
• On uPortal 2.5—Run ant deployPortletApp -DportletApp=
/path/to/PhotoDirectory.war
Session ID 4271 44
![Page 45: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/45.jpg)
Summary
The portlet API is defined by the JSR portlet specs:—request phases —portlet modes —window states —URL handling
• Portlets can be built once, and deployed to any compliant portal with little or no modification.
• MVC is a design pattern that separates presentation from business logic
• Portlets built using the Spring MVC framework can be simple or complex. Using JSP views you could create a portlet that doesn’t require any java coding.
Session ID 4271 4545
![Page 46: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/46.jpg)
Summary - Continued
• To deploy a Spring MVC portlet
— setup a dev environment
— setup the directory structure
— include the spring libraries
— configure the application context (portlet, web, and myPortlet-portlet.xml)
— use annotations to define controller and handler mappings
— create the controllers and domain objects
— create the service layer
— create the views (we used JSP views)
— deploy!
Session ID 4271 46
![Page 47: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/47.jpg)
Questions & Answers
?
Session ID 4271 47
![Page 48: Developing Portlets](https://reader034.vdocument.in/reader034/viewer/2022042706/58b8a50d1a28abc06d8b5ce1/html5/thumbnails/48.jpg)
Session ID 4271 48
SunGard or its subsidiaries in the U.S. and other countries is the owner of numerous marks, including “SunGard,” the SunGard logo, “Banner,” “PowerCAMPUS,” “Advance,” “Luminis,” "DegreeWorks," "fsaATLAS," “Course Signals,” and “Open Digital Campus.” Other names and marks used in this material are owned by third parties. © 2011 SunGard. All rights reserved.
Session Sponsor
Thank You!
Michael [email protected]
Please complete the online Session evaluation formSession ID 4271