Home >Documents >Developing Portlets

Developing Portlets

Date post:03-Mar-2017
Category:
View:20 times
Download:0 times
Share this document with a friend
Transcript:
  • Developing Portlets With the Spring MVC FrameworkPresented by: Michael SlavenTeachers College, Columbia UniversityMarch 21st, 2011Session ID 4271

    *

  • Session Rules of EtiquettePlease turn off your cell phone/pagerIf you must leave the session early, be sure not to knock over anyones coffee.If you must yawn or snore, please do so as discreetly as possible.Session ID 4271*

    *

  • AgendaSome 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, controllerSession ID 4271*

    *

  • Agenda - continuedPutting it all together

    Setting up a dev environment and directory structureConfiguring Spring and annotationsCreating the ViewControllerCreating the DirectoryServiceCreate the JSP views search and searchresultsDeployment

    Session ID 4271*

    *

  • About Teachers CollegeThe oldest and largest graduate school of education in the U.S.Affiliated with Columbia UniversityLocated in the northern end of Manhattan~5400 students~1000 staff165 full time faculty

    Session ID 4271*

    *

  • Some examples of portlets built using the Spring MVC framework

    *

  • The myTC Message CenterOur most recent (and biggest) Spring MVC portletSession ID 4271 *

    *

  • Session ID 4271 *

    *

  • Session ID 4271 *

    *

  • Features of the myTC Message CenterUses 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 *

    *

  • The myTC Photo DirectoryOur first (and smallest) Spring MVC portlet

    More Options allows search bytitle, office, phone, email, role(staff, student or faculty)Session ID 4271 *

    *

  • Session ID 4271 *Why portlets?Why Spring MVC?

    rvenable (rv) - I don't think you need the session id on this title slide.

    *

  • 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 doesnt support channels)

    Session ID 4271 *

    *

  • 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 *

    *

  • An overview of the JSR portlet specs

    *

  • JSR 168 and JSR 286 Portlet SpecsJSR 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 2008supported by Luminis 5

    Session ID 4271 *

    *

  • Request PhasesAction requests

    can be used to change system stateexecuted only onceproduces no markup

    Render requests

    Cannot change system stateexecuted at least onceproduces markup

    Event requests (Portlet 2.0 only)Resource requests (Portlet 2.0 only)

    Session ID 4271 *

    *

  • Request Handling Sequence (from JSR 286 spec)

    Session ID 4271 *

    *

  • Portlet ModesModes specify the current function of the portlet. There are three standard portlet modes:

    VIEW: normal modeEDIT: edit mode, for portlet specific preferencesHELP: 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 portlets toolbar, or they can be changed programmatically.

    Session ID 4271 *

    *

  • Window StatesWindow 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 windowMINIMIZED: smallest window, usually only a toolbar remains

    These can be changed by the user, usually with an icon in the portlets toolbar, or they can be changed programmatically.

    Session ID 4271 *

    *

  • URL HandlingThere 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 *

    *

  • An overview of the Spring MVC framework

    *

  • 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 theuser interface (view).

    Session ID 4271 *

    *

  • Model The M in MVCThe 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 *

    *

  • Views The V in MVCThe 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 *

    *

  • 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 *

    *

  • Putting it all together

    *

  • Photo Directory LiteOur 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, etcSEARCHRESULTS: the results, paginated 5 at a timeHas a single domain object:

    DirectoryEntry: setters and getters for a single entry in the photo directoryHas a single controller

    Has a single DB service object

    Session ID 4271 *

    *

  • Notes on setting up a dev environmentInstall the JDK and set JAVA_HOME

    JRE is not enough

    Install an IDE

    EclipseNetBeansUse Maven to simplify dependencies, building, and deploying

    Install a portal / portlet container

    uPortal 2.5.6 is best if developing for Lum 4Liferay 5.2.x is best if developing for Lum 5Or you can use Pluto from ApacheSession ID 4271 *

    *

  • 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 *

    *

  • Include the Spring librariesSession ID 4271 *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.

    *

  • Configure portlet.xmlThe Spring DispatcherPortlet dispatches requests to your controllers.

    This will be the same for any Spring portlet.

    Session ID 4271 *

    *

  • Configure web.xmlSpring 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 *

  • Configure PhotoDirectory-portlet.xml -- Annotations --Setup DefaultAnnotationHandlerMapping.

    Tell Spring where to scan for annotations like @Controller, @RequestMapping, @Autowired etc.

    Session ID 4271 *

  • Configure PhotoDirectory-portlet.xml -- View Resolver --Using JstlView we dont 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 *

  • Controller & Handler MappingWith Spring 2.5+ we can simplify by using annotations.

    Without annotations:

    The controller needs to extend a base controller likeAbstractController. 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 *

    *

  • ViewControllerSession ID 4271 *

    *

  • ViewController - ContinuedSession ID 4271 *

    *

  • DirectoryServiceImpl.javaSession ID 4271 *

    *

  • DirectoryServiceImpl.java - Continued

    Session ID 4271 *

    *

  • DirectoryServiceImpl.java - Continued

    Session ID 4271 *

  • VIEW: search.jsp

    Session ID 4271 *

  • VIEW: searchresults.jsp

    Session ID 4271 *

  • Deploy!Use Maven or Ant to package your portlet into a deployable war file.

    On Lum 4

    Run cptool

Click here to load reader

Embed Size (px)
Recommended