Using Pluto to develop portlets in Eclipse

Source: Internet
Author: User
Tags tomcat server
[Pre] uses eclipse plus Pluto to develop your first JSR168-compliant portlet
by Terry.li
Spiritseekers@sqatester.com[/pre]

This article describes developing Portlet applications based on Portlet Specification v1.0 (JSR168).
We use Pluto as a portlet container and portal. The development Portlet application can also be migrated to any portlet container that supports JSR168.

· Why do you want to publish the Portlet specification? What is JSR168?
As more and more companies develop their portal components and their portal offerings (such as Bea, IBM, Oracle, Sun, Sybase, Novell, SAP, Jetspeed, Vignette And so on. This incompatible interface implementation continues to bring problems and troubles to the provider, and in order to solve this problem, JCP publishes JSP168 (Java specification Request), Portlet specification, To provide interoperability between different portal and Portlets

· What is Portal?
Portal is a web-based application that consolidates and presents different resources to the user
Usually it has the following three features:

A. Personalization (personalized)
B. Single sign On (Point Landing)
C. Content Aggregation (contents aggregation)

Content aggregation refers to the integration of different sources of information into one page to make it easier for users to use.
For example, if a customer needs to make a commercial purchase, they need to visit different suppliers ' home pages to get relevant information, but if you use portal to integrate the merchandise catalog pages of all the different goods suppliers into a catalog portal page, Then all the merchandise information can be faster browsing, screening and ordering, speed up the customer's business operation efficiency.

· What is a portlet?
A portlet is a Java technology based on a Web component that is managed by the Portlet container. Process the request and dynamically return the page, which can be used as a pluggable user interface component of the portal.

· What is a portlet Container? The Portlet container is used to manage the lifecycle of the portlet and to provide the necessary environment for its operation. and provides a persistent (persistent) Access service for the Portlet preferences. But it does not support the aggregation of content. The aggregation is provided by the portal component.

Note: The Portlet preferences is a new feature of the portlet, providing functionality similar to the database. But not to replace the database. is simply used to access a simple portlet parameter configuration.

· What is WSRP?
WSRP is the abbreviation for the OASIS Web Service for Remote portlets. WSRP is designed to simplify the complexities of portal integration for a variety of resources or programs, and to avoid the complexity of the integration that programming brings. And the administrator of the portal can choose from a large number of services that need to be used to complete and into the portal.


· Portlet and Servlet

Excerpt from (Portlet Specs v1.0)

Same point:
Portlets are Java technology based Web Components
Portlets are managed by a specialized container
portlets Generate dynamic content
portlets Lifecycle is managed by a container
portlets interact with Web client via a request/response paradigm

Different points:
portlets only generate 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 a more refined request handling, action requests and render requests
portlets have predefined portlet modes and window states that indicate the function of the portlet is performing and am Ount of real state in the portal page
portlets can exist many times in a portal page

Portlet Specific:
portlets have 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 within their content, which allow Portal Server agnostic C Reation of links and actions in page fragments
portlets can store transient data in the Portlet sessions in two different scopes:the application-wide scope and the Por Tlet Private Scope

Servlet-specific:
Setting the character set encoding of the response
setting HTTP headers on the response
the URL of the client request to the portal

· What is Pluto?
Pluto is an open source project under Apache development and is an implementation of a portlet Container based on portlet specs. It also provides a sample portal implementation. But the function is relatively simple:

For example
1) There is no complex layout implementation.
2) is not multi-user enabled, for example, the portlet between different user preferences can be share to each other.

Keep in mind that Pluto is only a portlet container implementation, not a portal implementation. If you need a more powerful portal, you can use Jetspeed, which is also an open Source Project for Apache. Please refer to the resource section at the end of the article.

· Concept
Figure: Figure 1.1
A. Decorations and controls (cosmetic and control parts)
B. Portlet fragment (Portlet fragment)
C. portlet windows (portlet window)
D. Portlet page (portlet pages)



Figure 1.1

· Development tools (Eclipse2.1, Pluto-plugin, jakarta-tomcat-4.1.29)
Download Address:
Eclipse
http://www.eclipse.org/downloads/index.php

Pluto-plugin
Http://prdownloads.sourceforge.net/plutoeclipse/org.eclipsefan.pluto.ui_1.0.0.zip?download

Tomcat4.1
Http://mirrors.midco.net/pub/apache.org/jakarta/tomcat-4/v4.1.29/bin/jakarta-tomcat-4.1.29.zip

JDK1.4
Http://Java.sun.com

· Configuring the development environment
STEP1: Decompression Eclipse-sdk-2.1.1-win32.zip
STEP2: Unzip the org.eclipsefan.pluto.ui_1.0.0.zip and copy it into the Eclipse/plugins directory
Under, as follows: eclipse/plugins/org.eclipsefan.pluto.ui_1.0.0/
/icon
/lib
/source
/webapp
...
STEP3: Extract tomat4.1 to one directory. and configure the Tomcat server.
Congratulations, it ' s done!

A. Using Portlet Wizard to create Portal
1 Select File > New > Project ... > Portal > Pluto Portal Application, click Next, as shown:

Figure 1.2

2 Specify the project name (Figure 1.3), use Pluto here, and then click Next.

Figure 1.3




3 Specifies the Tomcat path, click Finish. Eclipse then installs Pluto on Tomcat and configures the environment automatically.

Figure 1.4




B. Creating Portlets Application


1 Create the Pluto portlet application (Figure Figure 1.5)

Figure 1.5

2 Enter the project name (figure Figure 1.6), with portlets

Figure 1.6




C. The final project was generated as shown in figure (Figure 1.7):

Figure 1.7
d. Generate/Update web.xml via Portlet.xml (Figure figure 1.8)

Figure 1.8

E. Deployment of Portlets

1 Compile portlets project.
2 under [Your Tomcat installation Directory]/webapps, create a new directory Portlets
3) All documents under the Web-root directory under the Portlets project are copied into the new portlets directory above.
TIP: If you are tired of CTRL + C and CTRL + V after each modification, you can make a bat file yourself under the Portlets Engineering directory, and then you can see it in Package Explorer in Eclipse and double-click on it. As shown above (Figure 1.8): The Deploy.bat file is the one that implements its function.

4) Start Tomcat.
5 in IE Input: http://localhost:8080/pluto/portal, you should be able to see the portal page.


· Sample Portlet
During the Portlets engineering file creation process, many files are generated automatically, including a simple portlet, and we look at the generated sample portlet.


1) Very similar to the servlet, the portlet extends from the Genericportlet

Import javax.portlet.*;

public class Simpleportlet extends Genericportlet

2 The three methods correspond to the three joins in the Portlet title bar (View, Edit, help)

public void Doview (...)

public void Doedit (...)

public void Dohelp (...)


Figure 1.9

3 Three methods call three JSP files to generate Portlet fragment, as well as invoke the servlet to generate portlet fragment. Similar to the servlet application, you can also use the
Getinitparameter (String s) method to get the initial value of the Portlet in the configuration file. Only the servlet uses Web.xml, and the portlet uses portlet.xml files.


Portlet.xml

<init-param>
<name>jspView</name>
<value>/jsp/view.jsp</value>
</init-param>


Simpleportlet.java

String Jspname =
Getportletconfig (). Getinitparameter ("Jspview");


· Portlet Tag Library

1) defineobjects Tag

If you open one of these JSP files, you will find that, like the servlet, some of the variables of the portlet can be used in the JSP. For example:

Renderresponse
Renderrequest
Portletconfig

But you have to be famous:
<portlet:defineObjects/>
It is not possible to define any attributes or contain any content.

2) ActionURL Tag
attribute value type corresponding value
WindowState String minimized, normal, maximized
Portletmode String View, edit, Help
var String any value
Secure String True,false

<portlet:actionurl windowstate= "Normal" portletmode= "edit" >
<portlet:param name= "Action" value= "login"/>
</portlet:actionURL>

Creates an action URL that, when accessed, causes the Portlet window to become normal, and the schema changes to edit.

3) Renderurl Tag
attribute value type corresponding value
WindowState String minimized,normal,maximized
Portletmode String View, edit, Help
var String any value
Secure String True,false

<portlet:renderurl portletmode= "View" windowstate= "maximized" >
<portlet:param name= "Number" value= "1"/>
<portlet:param name= "page" value= "2"/>
</portlet:renderURL>

Creates a render URL that, when accessed, makes the Portlet window maximized and the schema becomes view.

4) Namespace Tag
Produces a unique value for the current portlet. Prevents conflicts with value on other portlets or portal pages.
<a href= "javascript: <portlet:namespace/>dofoo ()" >Foo</A>

5) Param Tag
Property value type
Name String
<portlet:param name= "Myparam" value= "somevalue"/>
Note: param tag can not have body content.


Summary
Pluto is currently v1.0, and some of the portlet specifications are not fully implemented, for example, Renderresponse.settitle (), and you can download the latest Pluto code from Apache CVS, Hopefully this article will help you build a simple portlet development environment that is familiar with portlet-related knowledge.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.