+ All Categories
Home > Documents > Create a Sample Portlet With Eclipse

Create a Sample Portlet With Eclipse

Date post: 29-Nov-2014
Category:
Upload: saad-na
View: 158 times
Download: 2 times
Share this document with a friend
22
Hands-On Lab Lab Manual A quick Portlet tutorial Page i
Transcript
Page 1: Create a Sample Portlet With Eclipse

Hands-On LabLab Manual

A quick Portlet tutorial

Page i

Page 2: Create a Sample Portlet With Eclipse

ContentsA quick Portlet tutorial................................................................................................................................. i

LAB 01: A QUICK PORTLET TUTORIAL.........................................................................................................3Lab Objectives................................................................................................................................................ 3Exercise 1 – Downloading and installing eclipse and plugins.........................................................................3

1. Setup the eclipse and GlassFish.......................................................................................................32. Configure the server for eclipse.........................................................................................................3

Exercise 2 – Create web application BodyCheck...........................................................................................51. Create a Dynamic Web Application...................................................................................................52. Modify context path into the path of portlet container........................................................................63. Create portlet BodyCheck.................................................................................................................. 74. Input information for BodyCheck portlet.............................................................................................85. The generated source codes are as below:.......................................................................................86. Run the web application....................................................................................................................87. Open the portlet in the browser.........................................................................................................9

LAB 02: DEPLOY THE PORTLET INTO THE UPORTAL.................................................................................9Lab Objectives................................................................................................................................................ 9

Exercise 1 – Pack the portlet....................................................................................................................101. Export the .war file........................................................................................................................... 102. Deploy the BodyCheckPortlet.war into the uPortal..........................................................................10Exercise 2 – Publish the portlet................................................................................................................101. Login the uPortal with account admin/admin ()................................................................................102. Select Portlet Manager.................................................................................................................... 113. In the Channel Manager, select Portlet............................................................................................114. Input information for the project:......................................................................................................125. Input the “Portlet Descriptor”.........................................................................................................126. Select categories............................................................................................................................. 127. Select the groups and persons should have access to this portlet..................................................138. Click on Done link............................................................................................................................ 139. Try to use the portlet........................................................................................................................ 14

LAB 03: APPLY THE JSTL FOR THE PORTLET...........................................................................................17Lab Objectives.............................................................................................................................................. 17

Exercise 1 – Modify the JSP for compatibility with portlet version 1.0......................................................171. Modify taglib portlet for compatibility with portlet version 1.0...........................................................17Exercise 2 – Add library jstl...................................................................................................................... 171. Download and copy “jstl-1.1.2.jar”, “standard-1.1.2.jar” into BodyCheckPortlet\WebContent\WEB-INF\lib....................................................................................................................................................... 172. Update BodyCheckPortlet_view.jsp.................................................................................................173. Update BodyCheckPortlet.java........................................................................................................18

APPENDIX....................................................................................................................................................... 191. Setup the Sun GlassFish Enterprise Server 2.1..............................................................................192. Install Porlet Container for GlassFish..............................................................................................203. Change the layout of home page of uPortal....................................................................................204. Setup the plugins for Eclipse...........................................................................................................20

Page ii

Page 3: Create a Sample Portlet With Eclipse

Lab 01: A quick portlet tutorialEstimated time to complete this lab: 45 minutes

Lab Objectives

The objective of this lab is to introduce you how to create a simple portlet.

Downloading and installing eclipse and plugins.

Writing a simple portlet BodyCheck.

References:- \\rai-server\Supports\Tools\jPackages\eclipse-jee-galileo-SR1-win32-rocky.zip

Exercise 1 – Downloading and installing eclipse and plugins1. Setup the eclipse and GlassFish

This lab uses these softwares:

- Eclipse IDE for Java EE Developers and plugins Eclipse Portal Pack 2.0.1.- GlassFish v2.1 Java EE 5 ()

Refer more details in Appendix.

2. Configure the server for eclipse

Open the Preferences dialog by going to menu Window > Preferences. Select node Server\Runtime Environment.

Page 4: Create a Sample Portlet With Eclipse

Click on “Add…” button.

In the “New Server Runtime Environment”, select node “Sun Microsystems\OpenPortal Porlet Container 2.x”

Click on “Browse...” button to select GlassFish Home.

Click on Finish button.

The OpenPortal Porlet Container

Page 5: Create a Sample Portlet With Eclipse

Exercise 2 – Create web application BodyCheck3. Create a Dynamic Web Application

Going to menu File > New > Dynamic Web Project. Input the Project name. Click on Next twice.

Select “Porlet 1.0 support” in Configuration

Page 6: Create a Sample Portlet With Eclipse

4. Modify context path into the path of portlet container

Change the Context root to “portletdriver/dt”. This helps the eclipse open the home page of the open portlet container when start the project.

Click on Finish button. The structure of the project is:

Page 7: Create a Sample Portlet With Eclipse

5. Create portlet BodyCheck

Going menu New > Other…, select node Porlet\Java Porlet.

Click on Next button.

6. Input information for BodyCheck portlet

7. The generated source codes are as below:

Page 8: Create a Sample Portlet With Eclipse

8. Run the web application

Right-click on the project, select Run As > Run on Server.

Select server “OpenPortal Portlet Container”.

Then click on Finish button.

Page 9: Create a Sample Portlet With Eclipse

9. Open the portlet in the browser

Open the browser with the URL: http://localhost:8080/portletdriver/dt

Lab 02: Deploy the portlet into the uPortalEstimated time to complete this lab: 30 minutes

Lab Objectives

The objective of this lab is to introduce you how to deploy the portlet into uPortal

Pack the portlet into the .war file.

Deploy the portlet into the uPortal manually.

Deploy the portlet into the uPortal by ant command.

Exercise 1 – Pack the portlet

1. Export the .war file

Right-click on the project, select Export > WAR file.

Here is the content BodyCheckPortlet

Page 10: Create a Sample Portlet With Eclipse

2. Deploy the BodyCheckPortlet.war into the uPortal

Using ant command

From the folder $uPortal_HOME, execute command

ant deployPortletApp -DportletApp=<Path of .war file>

In there, <Path of .war file> is the path of BodyCheckPortlet.war.

Ex:

ant deployPortletApp -DportletApp="D:/Projects/BodyCheckPortlet/dist/BodyCheckPortlet.war"

Note: Please read “README” file to know how modify “build.properties” of uPortal.

Exercise 2 – Publish the portlet

1. Login the uPortal with account admin/admin (1).

1 http://www.uportal.org

Page 11: Create a Sample Portlet With Eclipse

2. Select Portlet Manager

3. In the Channel Manager, select Portlet.

Page 12: Create a Sample Portlet With Eclipse

Click on Next button

4. Input information for the project:

Channel Title: BodyCheckPortlet

Dynamic Title: checked

Channel Name: BodyCheckPortlet

Channel Functional Name

Channel Description: BodyCheckPortlet

Channel Timeout: 5000

Channel Secure: no check

Click on Next button

5. Input the “Portlet Descriptor”

Framework Portlet: false

Portlet Web Application Path: /BodyCheckPortlet

Portlet Name: BodyCheckPortlet

Click on Next button four times.

6. Select categories

Check on the Development. Then click on “Select Marked”.

Page 13: Create a Sample Portlet With Eclipse

Click on Next button.

7. Select the groups and persons should have access to this portlet

Check on “Close Group”. Then click on “Select Marked”.

Click on Next button. Then click on the Finished button.

8. Click on Done link.

Page 14: Create a Sample Portlet With Eclipse

9. Try to use the portlet

Click on tab “Testing”. Then click on Add tab.

Click on Add Content

Page 15: Create a Sample Portlet With Eclipse

Select Development > BodyCheck.

Click on Add to my page.

The portlet is displayed as below:

Page 16: Create a Sample Portlet With Eclipse

Refer Appendix.3 to change layout of home page of uPortal.

Page 17: Create a Sample Portlet With Eclipse

Lab 03: Apply the JSTL for the portletEstimated time to complete this lab: 30 minutes

Lab Objectives

The objective of this lab is to introduce you how to use upgrade the BodyCheckPortlet.

Exercise 1 – Modify the JSP for compatibility with portlet version 1.0

1. Modify taglib portlet for compatibility with portlet version 1.0.

For all JSP files, replace line

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>

By

<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>

The content of file BodyCheckPortlet\WebContent\WEB-INF\jsp\BodyCheckPortlet_view.jsp after updated:<%@page contentType="text/html"%><%@page pageEncoding="UTF-8"%>

<%-- Uncomment below lines to add portlet taglibs to jsp --%><%@ page import="javax.portlet.*"%><%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>

< portlet:defineObjects />

<b> Body Checking

</b>

Now, you should to re-deploy the portlet to view the changes.

Exercise 2 – Add library jstl

1. Download and copy “jstl-1.1.2.jar”, “standard-1.1.2.jar” into BodyCheckPortlet\WebContent\WEB-INF\lib.

2. Update BodyCheckPortlet_view.jsp

<%@page contentType="text/html"%><%@page pageEncoding="UTF-8"%>

<%-- Add portlet taglibs to jsp --%><%@ page import="javax.portlet.*"%><%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%><%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%><%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%>

< portlet:defineObjects />

< b > Body Checking <br/> < form action = ' < portlet:actionURL /> ' method = "POST" > Height(m)(*):<input name="height" value="${height}"/> <br/> Weight(kg)(*):<input name="weight" value="${weight}"/>

Page 18: Create a Sample Portlet With Eclipse

<br/> <input type="submit" name="cmd" value="Check"/> <br/> <b>${status}</b>

</form>

3. Update BodyCheckPortlet.java

public class BodyCheckPortlet extends GenericPortlet { final static Logger LOG = Logger.getLogger("BodyCheckPortlet"); private String status = "";

public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { LOG.info("doView.START"); response.setContentType("text/html"); request.setAttribute("status", status); PortletRequestDispatcher dispatcher = getPortletContext().getRe-questDispatcher( "/WEB-INF/jsp/BodyCheckPortlet_view.jsp");

dispatcher.include(request, response); LOG.info("doView.END"); }

public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException {

response.setContentType("text/html");

PortletRequestDispatcher dispatcher = getPortletContext().getRe-questDispatcher( "/WEB-INF/jsp/BodyCheckPortlet_edit.jsp"); dispatcher.include(request, response);

}

public void doHelp(RenderRequest request, RenderResponse response) throws PortletException, IOException {

response.setContentType("text/html");

PortletRequestDispatcher dispatcher = getPortletContext(). getRequestDispatcher("/WEB-INF/jsp/BodyCheckPortlet_help.jsp"); dispatcher.include(request, response);

}

public void processAction(ActionRequest request, ActionResponse re-sponse) throws PortletException, IOException { LOG.info("processAction.START"); String height = request.getParameter("height"); String weight = request.getParameter("weight"); LOG.info("height=" + height + ";weight=" + weight); status = "Default value: Normal"; LOG.info("processAction.END"); }

}

Appendix4. Setup the Sun GlassFish Enterprise Server 2.1

Page 19: Create a Sample Portlet With Eclipse

Download java-tools-bundle-update7-windows.exe (2) and run it. Select “Customize…” to install the Sun GlassFish Enterprise Server v2.1.

Check on two items “Sun GlassFish Enterprise Server v2.1” and “Portlet Container 2.1” only.

Follow the screen guideline in next steps.

To avoid conflicting with Tomcat in case they run parallelly, you can change ports:

HTTP Port: 7070

HTTPS Port: 7171

2 Download the lastest version at http://java.sun.com/javaee/downloads/previous/index.jsp?userOsIndex=6&userOsId=windows&userOsName=Windows. In the Intranet, it is already downloaded at\\rai-server\Supports\Tools\Java\ApplicationServers\java-tools-bundle-update7-windows.exe

Page 20: Create a Sample Portlet With Eclipse

Admin Port: 4747

5. Install Porlet Container for GlassFish

Copy files “setup.bat” and portlet-container-configurator.jar from “\\rai-server\Supports\Tools\Java\Portlet\” into your local PC. Run setup.bat. Input the home GlassFish Server into “Select Install Directory”. Then click on OK.

6. Change the layout of home page of uPortal

Login the uPortal by account guest-lo/guest-lo to change layout. Then restart the uPortal to apply changes.

7. Setup the plugins for Eclipse

In the intranet, the eclipse with installed plugins is at \\rai-server\Supports\Tools\jPackages\eclipse-jee-galileo-SR1-win32-rocky.zip.


Recommended