http://dev2dev.bea.com/pub/a/2004/02/JSR168.html
Developing JSR 168 Portlets with WebLogic Portal 8.1
by Alex Toussaint, Subbu Allamaraju
02/10/2004
JSR 168 (Java Portlet) is a Java specification that aims at establishing portability between portlets and portals. One of the main goals of the specification is to define a set of standard Java APIs for portal and portlet vendors. These APIs will cover areas such as presentation, aggregation, security, and portlet lifecycle.
As an application developer you should examine the different types of portlets that are available in WebLogic Portal 8.1 and decide which type is best suited for the task you are trying to accomplish. For example, if you are looking for a way to interface with Java Controls, leverage Struts-based infrastructure, and deliver rich navigation elements then your choice may be Java Page Flow portlets. If you are looking for just a simple portlet or converting an existing JSP page into a portlet you may consider using a JSP portlet. If you work for an independent software company or other enterprise that is concerned with portability across multiple portlet containers, then you may choose to use JSR 168 compliant Java portlets.
Below is a matrix to help you decide which implementation to use when building portlets:
There are two main components associated with the JSR 168 -- portlets and portlet containers.
The Portlet APIs defined in the JSR 168 share many concepts with servlet APIs:
Portlets differ from servlets in the following aspects:
Portlets also have access to the following extra functionality that is not provided by servlets:
The Portlet container is an extension of the Servlet container. The Portlet API v1.0 is based on the Java 2 Platform, Enterprise Edition, v1.3. Portlet containers and portlets meet the requirements for executing within a J2EE environment as described in the J2EE specification.
The Portlet container must use the same classloader that the servlet container uses for the Web application resources in order to load the portlets and related resources within the portlet application. The portlet container is responsible for informing portlets of user roles, but the portlet container does not deal with user authentication.
BEA has implemented the portlet container to be compliant with JSR 168. The BEA implementation takes advantage of all the capabilities of the WebLogic Application Server in the areas of failover, scalability, security, and hot deployment of portlets. The Portlet container will manage all the lifecycle phases of the portlets. The implementation itself consists of several jar files that can be added to the Portal Web application.
Figure 1: The typical flow of a request interacting with the Portlet Container
The portlet container supports the concept of Portlet Preferences. This allows one concrete portlet instance to be made available as logical instances to several users, and multiple instances per user, who in turn can customize the behavior and the look and feel associated with their logical instance. This infrastructure is already in place with WebLogic Portal 8.1 and it can be used with non-JSR168 portlets.
Below is an example of a JSR 168 compliant "Hello World" portlet:
Here is the portlet.xml file for the Hello World portlet:
The BEA WebLogic Portal team was actively involved with the expert group working on JSR 168. You can download the full implementaion of the JSR168 with the Weblogic Portal 8.1 SP2.
For more Information on the JSR 168 and BEA WebLogic Portal 8.1:
dev2dev BEA WebLogic Portal page:
http://dev2dev.bea.com/products/wlportal81/index.jsp
BEA WebLogic Portal documentation site:
http://edocs.bea.com/wlp/docs81/index.html
BEA WebLogic Portal Newsgroups:
http://newsgroups.bea.com/cgi-bin/dnewsweb?cmd=xover&group=WebLogic.developer.interest.portal&utag=
BEA WebLogic Portal product page:
http://www.bea.com/framework.jsp?CNT=index.htm&FP=/content/products/portal
JSR 168 Home:
http://www.jcp.org/en/jsr/detail?id=168
Using JSR 168 (Java) Portlets with WebLogic Portal 8.1
As an application developer you should examine the different types of portlets that are available in WebLogic Portal 8.1 and decide which type is best suited for the task you are trying to accomplish. For example, if you are looking for a way to interface with Java Controls, leverage Struts-based infrastructure, and deliver rich navigation elements then your choice may be Java Page Flow portlets. If you are looking for just a simple portlet or converting an existing JSP page into a portlet you may consider using a JSP portlet. If you work for an independent software company or other enterprise that is concerned with portability across multiple portlet containers, then you may choose to use JSR 168 compliant Java portlets.
Below is a matrix to help you decide which implementation to use when building portlets:
Portlet Types | Pros | Cons |
JSP or HTML based portlets |
|
|
JSR 168 based portlets |
|
|
Java Page Flow based portlets |
|
|
Components of the specification
There are two main components associated with the JSR 168 -- portlets and portlet containers.
- Portlet: A portlet is a Java technology based Web component, managed by a portlet container that processes requests and generates dynamic content. Portlets are used by portals as pluggable user interface components providing a presentation layer to information systems.
- Portlet Container: A portlet container provides portlets with the required runtime environment, managing their lifecycle and persistent storage for portlet preferences.
Java Portlets
The Portlet APIs defined in the JSR 168 share many concepts with servlet APIs:
- Portlets are Java technology-based web components.
- A specialized container manages Portlets and portlet lifecycle.
- Portlets generate dynamic content.
Portlets differ from servlets in the following aspects:
- Portlets generate only markup fragments, not complete documents. The Portal aggregates portlet markup fragments into a complete portal page.
- Portlets are not directly bound to a URL.
- Web clients interact with portlets through a portal system.
- Portlets have more refined request handling, action requests, and render requests.
- Portlets have predefined portlet modes and window states.
Portlets also have access to the following extra functionality that is not provided by servlets:
- Portlets have the means for accessing and storing persistent configuration and customization data.
- Portlets have access to user profile information.
- Portlets have URL rewriting functions for creating hyperlinks which allow portal server agnostic creation of links and actions in page fragments.
- Portlets can store transient data in the portlet session into two different scopes: the application-wide scope and the portlet private scope.
Java Portlet Container
The Portlet container is an extension of the Servlet container. The Portlet API v1.0 is based on the Java 2 Platform, Enterprise Edition, v1.3. Portlet containers and portlets meet the requirements for executing within a J2EE environment as described in the J2EE specification.
The Portlet container must use the same classloader that the servlet container uses for the Web application resources in order to load the portlets and related resources within the portlet application. The portlet container is responsible for informing portlets of user roles, but the portlet container does not deal with user authentication.
BEA Implementation Overview
BEA has implemented the portlet container to be compliant with JSR 168. The BEA implementation takes advantage of all the capabilities of the WebLogic Application Server in the areas of failover, scalability, security, and hot deployment of portlets. The Portlet container will manage all the lifecycle phases of the portlets. The implementation itself consists of several jar files that can be added to the Portal Web application.

The portlet container supports the concept of Portlet Preferences. This allows one concrete portlet instance to be made available as logical instances to several users, and multiple instances per user, who in turn can customize the behavior and the look and feel associated with their logical instance. This infrastructure is already in place with WebLogic Portal 8.1 and it can be used with non-JSR168 portlets.
JSR168 Hello World Portlet
Below is an example of a JSR 168 compliant "Hello World" portlet:
package examples.helloworld; import java.io.IOException; import javax.portlet.PortletException; import javax.portlet.GenericPortlet; import javax.portlet.RenderResponse; import javax.portlet.RenderRequest; public class HelloWorld extends GenericPortlet { public void render(RenderRequest request, RenderResponse response) throws PortletException, IOException { response.getWriter().write("<p>Hello World</p>"); } } |
Here is the portlet.xml file for the Hello World portlet:
<?xml version="1.0" encoding="UTF-8"?> <portlet-app version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://java.sun.com/xml/ns/portlet" xmlns="http://java.sun.com/xml/ns/portlet"> <portlet> <portlet-name>helloWorld</portlet-name> <portlet-class>examples.helloworld.HelloWorld</portlet-class> <portlet-info> <title>Hello World</title> </portlet-info> </portlet> </portlet-app> |
Summary
The BEA WebLogic Portal team was actively involved with the expert group working on JSR 168. You can download the full implementaion of the JSR168 with the Weblogic Portal 8.1 SP2.
For more Information on the JSR 168 and BEA WebLogic Portal 8.1:
dev2dev BEA WebLogic Portal page:
http://dev2dev.bea.com/products/wlportal81/index.jsp
BEA WebLogic Portal documentation site:
http://edocs.bea.com/wlp/docs81/index.html
BEA WebLogic Portal Newsgroups:
http://newsgroups.bea.com/cgi-bin/dnewsweb?cmd=xover&group=WebLogic.developer.interest.portal&utag=
BEA WebLogic Portal product page:
http://www.bea.com/framework.jsp?CNT=index.htm&FP=/content/products/portal
JSR 168 Home:
http://www.jcp.org/en/jsr/detail?id=168