kapok

垃圾桶,嘿嘿,我藏的这么深你们还能找到啊,真牛!

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  455 随笔 :: 0 文章 :: 76 评论 :: 0 Trackbacks

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.

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
  • Simple to implement and deploy
  • Provides basic functionality without a lot of complexity
  • Business logic and presentation layer can get combined in JSPs
  • Not well suited for advanced portlet navigation
JSR 168 based portlets
  • Accommodate portability for portlets across platforms
  • Does not require use of portal server specific JSP tags
  • Behavior is similar to a Servlet
  • Does not leverage BEA advanced portlet features
  • Requires deeper understanding of J2EE programming model
Java Page Flow based portlets
  • Allow you to separate the user interface code from navigation control and other business logic
  • Provides the ability to model both simple and advanced portlet navigation
  • Allow you to quickly leverage Java Controls, Web Services, and Business Processes
  • Provides a visual environment to build rich applications based on Struts
  • Advanced Pageflow features not necessary for static or simple, one view portlets


Components of the specification


There are two main components associated with the JSR 168 -- portlets and portlet containers.

  1. 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.
  2. 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:

  1. Portlets are Java technology-based web components.
  2. A specialized container manages Portlets and portlet lifecycle.
  3. Portlets generate dynamic content.

Portlets differ from servlets in the following aspects:

  1. Portlets generate only markup fragments, not complete documents. The Portal aggregates portlet markup fragments into a complete portal page.
  2. Portlets are not directly bound to a URL.
  3. Web clients interact with portlets through a portal system.
  4. Portlets have more refined request handling, action requests, and render requests.
  5. Portlets have predefined portlet modes and window states.

Portlets also have access to the following extra functionality that is not provided by servlets:

  1. Portlets have the means for accessing and storing persistent configuration and customization data.
  2. Portlets have access to user profile information.
  3. Portlets have URL rewriting functions for creating hyperlinks which allow portal server agnostic creation of links and actions in page fragments.
  4. 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.

Figure 1: The typical flow of a request interacting with the Portlet Container

1


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

posted on 2005-04-21 13:27 笨笨 阅读(473) 评论(0)  编辑  收藏 所属分类: J2EEALLWeblogic Portal

只有注册用户登录后才能发表评论。


网站导航: