Download How to create Java portlets that comply with the

yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
How to create Java portlets that comply with the Java Portlet Specification for
Creating Java portlets that comply with the Java Portlet Specification and importing them to the
Java portlets that comply with the Java Portlet Specification can be imported and used in the
Dashboard. To maintain a reasonable separation between standard Dashboard/Center code and
custom portlet code, it is a good idea to create a separate Web archive for custom portlets. This
document describes how to set up a separate Web archive and deploy custom portlets to it such that
they can be successfully imported into the Dashboard.
Implement your portlet
Portlets must be coded according to the Java Portlet Specification (JSR 168 - see As a running example in this document, say you have
coded a Java portlet called "my.package.MyPortletClass," which is a subclass of
Create a Web archive for your portlet
You need to create a new Web archive in which to deploy your Java portlet. Create a new directory in
the deploy area of tour Application Server for your archive -- "myWebArchive.war" for this example.
On the Application server:
$ ls server/.../deploy
You should create the following subdirectories under myWebArchive.war/:
 WEB-INF/classes/
 WEB_INF/lib/
Deploy the portlet Java code to your Web archive
All deployed Java code and configuration files belong in the WEB-INF/ subdirectory of your Web
archive. The XML configuration files (described in the following sections) will be placed directly in
WEB-INF/, and Java code must be deployed under the WEB-INF/classes/ subdirectory. Under the
WEB-INF/classes/ subdirectory, create the package structure for your portlet's Java code, and copy
the Java files to the appropriate location.
On the Application server:
$ ls server/.../deploy/myWebArchive.war/classes/my/package/
In addition, in order for the Dashboard to correctly process your portlet, you will need to make the
portlet-wrapper.jar file available to your Web archive. This archive is available in the Dashboard
distribution lib directory. Copy it from there to the WEB-INF/lib/ subdirectory of your WAR.
Place any other prepackaged Java libraries needed by your portlet in the WEB-INF/lib/ subdirectory,
along with portlet-wrapper.jar.
Create the deployment descriptor file "portlet.xml"
This descriptor file defines the meta information need by the portlet container to run your portlet. Add
or modify this file in the WEB-INF/ directory of your WAR: ApplicationServer/server/.../deploy/myWebArchive.war/WEB-INF/.
Your portlet.xml should look like the following:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Specify a name you will use to refer to this portlet. -->
<!-- Specify initialization parameters.
Insert as many ?init-param? tags as necessary. -->
<!-- Specify how long (seconds) the portlet container
should cache this portlet?s content. -->
<!-- Specify the modes available for this portlet.
Available modes are "VIEW", "EDIT", and ?HELP?.
I think specifying "VIEW" mode isn?t required by the portlet spec (since all portlets have
a "VIEW" mode), but our architecture requires it otherwise your portlet won?t be displayed. <supports>
<!-- Specify the set of preferences (if any) for this portlet, and default values.
Insert as many ?preference? tags as necessary. -->
Add a servlet mapping to your Web descriptor file "web.xml"
Finally, you need to hook up your portlet to our central portlet-handling servlet, which is done in the
main Web configuration file web.xml (example shown below). Create or modify this file in the WEBINF/ directory of your WAR.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
<display-name>My Portlet</display-name>
<display-name>My Portlet</display-name>
<description>My Portlet Wrapper</description>
<!-- This is the servlet used for all Dashboard portlet processing, and must be specified exactly
as follows. -->
Add the location of your portlet to your center's <java-portlet-list-xml> configuration file. The
integrating center should create an XML configuration file that holds the list of deployed portlets -- an
example of such file would be java_portlet_list.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSPY v5 rel. 4 U ( -->
<portlet-list xmlns:xsi="" version ="2.0">
<!-- portlet-list... -->
The Dashboard should receive the list of Java portlets available for use; the way this is done is by
passing the "JAVA_PORTLET_LIST_PROPERTY_KEY" property in the getDashboardConfiguration
method. The value of this property must be a String representation of the portlet-list file:
try {
InputStream listStream =
if (listStream != null) {
byte[] buf = new byte[listStream.available()];;
props.setProperty(JAVA_PORTLET_LIST_PROPERTY_KEY, new String(bug));
} catch (IOException e) {
Make sure your center has such a file checked in somewhere, and add your portlet section to the
<!-- IMPORTANT NOTE: The portlet name specified here must match EXACTLY with the
portlet-name specified in portlet.xml. -->
<!-- Your portlet is deployed to your external WAR. -->
<!-- The servlet path must map to the URL pattern specified in web.xml. -->
<!-- Self-explanatory. Specify "true" if your portlet is web service-enabled. -->
Import the new portlet definition
To import, use the Dashboard portlet import wizard UI. Choose to import a "Java Portlet," and follow
the wizard instructions to choose your new portlet and import it. Once completed, this portlet should
be available to add from the Dashboard Personalization page.
It is important to note that JBoss's hot-deploy feature is not compatible with the Pluto portal. If you
hot-deploy the portlet, it will stop working for all of your users until you restart the application server.