Spring 3.1 Enabled Portlet With JPA

Embed Size (px)

Citation preview

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    1/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    Developing Spring based WebSpherePortal application using IBM RationalApplication Developer

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    2/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    Table of Content

    Abstract ..........................................................................................................................3

    Overview.........................................................................................................................3Sample Use case............................................................................................................3Prerequisite : ..................................................................................................................3Developing the spring portlet ..........................................................................................4

    Portlet project creation ................................................................................................4Spring configuration for portlet project ........................................................................5

    GUI development of the portlet .....................................................................................10Creation of JPA entities and Manager bean..............................................................10Updating ViewController and JSP file to integrate with JPA beans...........................14

    Deploying the portlet on WebSphere Portal..................................................................16Executing the use case on the server .......................................................................18

    Summary ......................................................................................................................19

    Resources ....................................................................................................................20

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    3/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    Abstract

    The aim of this article is to showcase development of Spring V3.1 based portlets for WebSpherePortal using IBM Rational Application Developer V8.5. The sample use case of this article

    incorporates fetching the data from a Derby database using JPA technology. It uses Spring 3.1portlet MVC framework, JSR 286 portlet specifications, JPA and Derby as database.

    The article is divided into two sections. The first section shows how to create a portlet project andthen configure it to consume Spring V3.1 framework. The second section is about creating UI forthe portlet that displays records fetched from Derby database using JPA tooling.

    Overview

    Spring is one of the most popular application development frameworks for enterprise Java that aidscreation of high performing, easily maintainable applications with reusable code. Spring is

    organized in a modular fashion. Spring's web or portlet framework is a well-designed MVCframework that lets you integrate with some of the existing technologies like object-relationalmapping (ORM), logging frameworks, and some of the popular view technologies. Spring offerslightweight inversion of control (IoC) containers as compared to EJB containers. Spring providesscalable transaction management interface. Traditionally, Spring framework has been in use forweb applications with application servers like WebSphere Application Server, but now its alsoused in portlet environment on WebSphere Portal Server to leverage the best of both.

    Sample Use caseYou will work with a portlet project that contains the Spring 3.1 libraries.The portlet is based onspring MVC architecture, and you will start with creating configuration files required to enable the

    project leverage the spring libraries. The project also interacts with a healthcaredatabaseby usingJPA tooling to fetch the list of hospitals from a database table, and finally you will publish theportlet project on WebSphere portal Server to display the results in a HTML table format.

    Prerequisite :To create the sample, install the following software:

    1)IBM Rational Application Developer version 8.52)IBM WebSphere Portal Server version 8.03)Spring libraries version 3.1.0

    On skill level, apart from knowledge about Spring, you should know how to work with IBMRational Application Developer and JPA technology to simplify the process of project creation.

    You can prepare the development environment by installing IBM Rational Application Developerv8.5 and WebSphere Portal Server v8.0. Download and store the Spring Framework 3.1.0 fromSpring Source Site.

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    4/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    Developing the spring portlet

    In this section, you will first create a portlet, and then make it leverage Spring framework.

    Portlet project creation

    To create a portlet project:

    1. Launch the Rational Application Developer in a new workspace.2. Select File->New->Portlet Project. The Project creation dialog (as shown in figure 1)

    opens.

    Figure 1: New portlet project wizard

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    5/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    Enter SpringJPASample as the name of the project name. Select WebSphere Portal v8.0 as your target runtime. Select the Create a portlet checkbox. Click the modify button of the Configuration label, and select JSR286 as portlet API and

    Empty portlet as Portlet type. Click Finish.

    The portlet project is created in the workspace.

    Spring configuration for portlet project

    To configure Spring framework:

    1)Copy the following Spring libraries into \WebContent\WEB-INF\lib folder as shown in figure2. The added libraries are:

    org.springframework.web.struts-3.1.0.M2.jar org.springframework.web.servlet-3.1.0.M2.jar org.springframework.web.portlet-3.1.0.M2.jar org.springframework.web-3.1.0.M2.jar org.springframework.transaction-3.1.0.M2.jar org.springframework.test-3.1.0.M2.jar org.springframework.spring-library-3.1.0.M2.libd org.springframework.oxm-3.1.0.M2.jar org.springframework.orm-3.1.0.M2.jar org.springframework.jms-3.1.0.M2.jar org.springframework.jdbc-3.1.0.M2.jar org.springframework.instrument.tomcat-3.1.0.M2.jar org.springframework.instrument-3.1.0.M2.jar org.springframework.expression-3.1.0.M2.jar org.springframework.core-3.1.0.M2.jar org.springframework.context.support-3.1.0.M2.jar org.springframework.context-3.1.0.M2.jar org.springframework.beans-3.1.0.M2.jar org.springframework.aspects-3.1.0.M2.jar org.springframework.asm-3.1.0.M2.jar org.springframework.aop-3.1.0.M2.jar commons-logging.jar

    Figure 2: Spring libraries in lib folder

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    6/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    2)Change the portlet class from the default one toorg.springframework.web.portlet.DispatcherPortlet: From the Enterprise Explorer view, open the Portlet Deployment Descriptor node (or open

    the file /WebContent/WEB-INF/portlet.xml). Select portlet tab, and select SpringJPASample portlet to view the details as shown in

    Figure 3. Click Browse button of Portlet class, and select

    org.springframework.web.portlet.DispatcherPortlet. Click OK and save the changes.

    Figure 3: Choosing Spring portlet class

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    7/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    Note: The dispatcher portlet class handles all the requests from client and renders the output.

    3)Create a XML file, SpringJPASample-portlet.xml in the folder \WebContent\WEB-INF\. Copythe code snippet 1 into it.

    Code Snippet 1: SpringJPASample-portlet.xml File

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    8/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    annotation, for e.g. @Controller annotation would enable the container to detect a designatedcontroller class.For every portlet that you create, there is a file with name -portlet.xml. When thedispatcher portlet is initialized, the framework refers to the portlet.xml file in the WEB-INFdirectory of your web application.

    4)The Spring based portlets require another configuration file called applicationContext.xml todefine the view resolver. To create the file:

    Right-click on the src folder and select New->Package, name it as context. Create a new XML file applicationContext.xml in the context package. Copy the content for code from snippet 2 to the file.

    Code Snippet 2 : applicationContext.xml file.

    In this file you have added:

    The View Resolver bean with class -org.springframework.web.servlet.view.InternalResourceViewResolver.

    The property viewClass with value org.springframework.web.servlet.view.JstlView,thatenables the Java Server Pages Standard Tag Library (JSTL) in the view.

    The property prefix points to the folder containing the view pages, and suffix points to thefolder that contains the extension of the view file.

    5) Add the reference of the applicationContext, listener, servlet and servlet mappings in the WebDeployment Descriptor. To add these references:

    Open the Web Deployment Descriptor node (or /WebContent/WEB-INF/web.xml file) Copy the code snippet 3 to the file before tag.

    Code Snippet 3: Web Deployment Descriptor

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    9/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    contextConfigLocation/WEB-INF/classes/context/applicationContext.xml

    org.springframework.web.context.ContextLoaderListener

    ViewRendererServletorg.springframework.web.servlet.ViewRendererServlet1

    ViewRendererServlet/WEB-INF/servlet/view

    In the Web deployment descriptor, you have made following changes: The context parameter is defined and mapped to the applicationContext.xml file. Listener is added and its class is set to,org.springframework.web.context.ContextLoaderListener. It loads the web applicationcontext at the startup of the web application.

    The servlet ViewRendererServlet is added, the servlet class is set toorg.springframework.web.servlet.ViewRendererServlet. This class bridges servlet for portletsupport. During the render phase, DispatcherPortlet wraps portlet request into servlet requestand forwards control to ViewRendererServlet. Servlet mapping is defined to the path /WEB-INF/servlet/view.

    6) Create a view controller class. To create the class file: Right-click the package com.ibm.springjpasample in Java Resources and select New->

    Class to create a class with name ViewController. Copy the following code snippet 4 to ViewController.java file.

    Code Snippet 4: ViewController class.

    package com.ibm.springjpasample;

    import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.portlet.ModelAndView;

    @Controllerpublic class ViewController {

    private static final String VIEW_PAGE ="SpringJSP";

    @RequestMapping("VIEW")public ModelAndView SpringJSP()

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    10/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    {try{System.out.println("Calling SpringJSP");}catch(Exception e){e.printStackTrace();}

    return new ModelAndView(VIEW_PAGE);}}

    Note the use of default annotations for controller and request mapping to allow framework torecognize the controller class, and the method that provides model and view.

    GUI development of the portlet

    So far you have configured the Spring framework for the portlet, and now you will work on theJSP file to create the GUI to display the data. In this use case you will use Java Persistent API(JPA) to fetch the data from a Derby database. The data fetched is displayed in a HTML table.

    1)Create the JSP page to render the view. To create the folder and add the JSP page: Right-click on the WEB-INF folder and select New -> Folder and name the folder as

    pages. Right-click on the pages folder and select New -> File to create a new JSP file by title

    SpringJSP.jsp.

    After adding the JSP page to the portlet project, you can add text to the JSP page and publishthe project on the server to test the configuration changes.

    Creation of JPA entities and Manager bean

    2)To integrate the application with the database server, you first need to establish the databaseconnection. Use the Healthcare database (provided with the sample app) for the use case, save it inC:\dbfolder. To establish the database connection:

    Open the Database Development perspective (Window -> Open Perspective). Right-click Database Connections in Data Source Explorer view, and select New. New Connection wizard (figure 4) displays, select Derby as the database manager. Select Derby 10.1- Embedded JDBC Driver Default as the Java Database Connectivity (JDBC)driver. Browse and select C:\db\HealthCareDatabase in the Database Location field. Click Finish, ensure that the connection works.

    Figure 4: New connection wizard

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    11/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    3)To fetch data from the database, create the JPA entities and Manager Beans using the JPA toolingprovided by Rational Application Developer. To create the JPA entitiy: In the Enterprise Explorer view, select the SpringJPASample project. Right-click and select JPA Tools -> Configure JPA Entities. The Configure JPA Entities windowinstalls the JPA 1.0 facet, if it is not installed. In Configure JPA Entities wizard, click Create New JPA Entities, the Generate Custom Entities(figure 5) wizard displays. Select the HealthCareDatabase in connections drop-down and APP in schema drop-down. Select the HOSPITAL table and click Finish. On the Configure JPA Entities wizard, select the Hospital entity and click Finish.

    In src folder, a package labeled entity is added and Hospital.java gets created in it.

    Figure 5: Generate custom entities

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    12/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    4) Add a named query to the JPA entity to fetch the Hospital list. To add the named query: Right-click the Portlet project and select JPA Tools -> Configure JPA Entities. Select the Hospital entity from the list of available entities and click Next. Select the Named Queries task (figure 6) and click Add. Accept the default values on the Add Named Query wizard and click OK In Configure JPA entities wizard, click Finish.

    The entity class Hospital.java gets annotated with the named query.

    Figure 6: Configure JPA entities

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    13/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    5)Create the JPA Manager bean for the Hospital entity. To create JPA Manager bean: Right-click the Portlet project and select JPA Tools -> Add JPA Manager Beans. In JPA Manager Bean wizard, click Finish.

    The HospitalManager.java gets created in src/entities/controller.

    6)To add the bean definition of HospitalManager to applicationContext.xml, copy the code snippet 5to applicationContext.xml file.

    Code Snippet 5: Bean definition of HospitalManager.

    7)Manually manage and provide the EntityManagerFactory required to run a jsp file which calls a JPAentity. You are not using resource injection which is container managed. To set theEnityManagerFactory: Create a new class EMFProvider in the package com.ibm.springjpasample.

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    14/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    Copy the code snippet 6 to it.

    Code Snippet 6: EMFProvider class.

    package com.ibm.springjpasample;

    import javax.persistence.EntityManagerFactory;import javax.persistence.Persistence;

    public class EMFProvider {private static EntityManagerFactory emf;private static final String project = "SpringJPASample";

    public EMFProvider() {

    }

    public static synchronized EntityManagerFactory getEMF() {if (emf == null) {emf = Persistence.createEntityManagerFactory(project);

    }return emf;

    }}

    Note:If you create the project with a different name, then give that value for the property project.

    8)Change the default constructor in HospitalManager.java file to set the EMFProvider. To changethe default constructor, replace it with the code snippet 7.

    Code Snippet 7: Default constructor for Hospital Manager bean.

    public HospitalManager() {this.emf =EMFProvider.getEMF();

    }

    Updating ViewController and JSP file to integrate with JPA beans

    9)Change the ViewController to class to work with the JPA entities, and provide the desired modeland view to ViewResolver. To implement the use case logic, copy the code snippet 8 to theViewController.java.

    Code Snippet 8: ViewController.java

    package com.ibm.springjpasample;

    import java.util.List;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.portlet.ModelAndView;

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    15/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    import entities.Hospital;import entities.controller.HospitalManager;

    @Controllerpublic class ViewController {private static final String VIEW_PAGE = "SpringJSP";

    @RequestMapping("VIEW")public ModelAndView springJSP(){ModelAndView mv = new ModelAndView(VIEW_PAGE);List hosList;ApplicationContext applicationContext = new

    ClassPathXmlApplicationContext("context/applicationContext.xml");HospitalManager hm1 =(HospitalManager)

    applicationContext.getBean("HospitalManager");hosList = hm1.getHospital();mv.addObject("objects",hosList);return mv;

    }}

    The method springJSP in ViewController class fetchs the list of hospital records using theHospitalManager bean. The list is added to model and view object with a key objectsandreturned to applicationContext for ViewResolver to display the output.

    10)To display the result in a HTML table format, make the following changes to the JSP page. Add the following taglib at top section of the page where taglibs are defined.

    Copy the code snippet 9 to the JSP

    Code Snippet 9 : HTML table to display the result

    NameAddressemailIdWebsite

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    16/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    The key objects used in conditional statement here is the same key that was used to store thehospital list in springJSP() in ViewController class.

    Deploying the portlet on WebSphere Portal

    Now you are all set to publish the portlet application on to WebSphere Portal. To publish theproject, create the server instance and start the server, in case it is not started. To create the serverinstance:

    1) Go to File -> New -> Other -> Server to launch the server creation wizard (shown in figure7).

    2) Select WebSphere Portal v8.0 Server and provide the hostname, click Next.

    Figure 7: Server creation wizard

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    17/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    3)On the WebSphere Settings wizard, provide the port numbers to connect to the server,server credentials, and click Next.4)On the Portal Settings wizard, provide the server credentials required to publish the projectto the server, and click Next.5)Click Finish.6)If server is not started, right-click the server instance created above and select Start.7)After the server starts, right-click on portlet project and select Run on server (figure 8) todisplay the Run On Server wizard.

    Figure 8: Run On Server option

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    18/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    8) In the Run On Server wizard, select the server instance that you created and click Finish.

    Executing the use case on the server

    The Run On Server wizard publishes the portlet project. It also places the portlet on a portal pagelabeled as Rational Components, and opens the browser instance rendering the portlet. You willhave the portlet SpringJPASample on the page displaying the list of hospitals with details, such asname, address, e-mail ID and website in a HTML table.

    See the figure 9 to view the table

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    19/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties, so the above limitations or exclusions may not apply to you. IBM shall not be liablefor any damages you suffer as a result of using, modifying or distributing the sample program or its derivatives.

    Figure 9: Table output shown in web browser

    Summary

    In this article you have learned how to integrate Spring framework based portlet application withWebSphere Portal by using IBM Rational Application Developer. The use case that you followedcreated a portlet project in IBM Rational Application Developer, and showed how to configure theportlet project using the Spring framework by adding the desired libraries. This was followed bycreation of required configuration files and accordingly creating an action class to implement the

    business logic to return the appropriate view. After the Spring configuration, you used JPA tocommunicate with Derby database by using JPA tooling provided by IBM Rational ApplicationDeveloper. Finally, to visualize and test the application, you designed the GUI in a JSP file andpublished the portlet project to WebSphere Portal Server.

  • 7/23/2019 Spring 3.1 Enabled Portlet With JPA

    20/20

    The sample program is provided to you on an "AS IS" basis, without warranty of any kind.IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.Some jurisdictions do not allow for the exclusion or limitation of implied warranties so the above limitations or exclusions may not apply to you IBM shall not be liable

    Resources

    1) Get information about Rational Application Developer and how to use it: What's new in Rational Application Developer v 8.0.3? IBM Rational Application Developer v8 Information center.

    2) For product documentation about WebSphere Portal Server v 7.0 Documentation link for WebSphere portal.

    3) How to download Spring libraries and its information: Spring downloads link for different releases. Spring release documentation.

    4) Apache OpenJPA http://openjpa.apache.org/

    5) The Java Persistence API - A Simpler Programming Model for Entity Persistence http://www.oracle.com/technetwork/articles/javaee/jpa-137156.html