Skip to main content

skip to main content

developerWorks  >  Sample IT projects  >

The making of MetroSphere, Part 13: Install an existing portlet

Adding functionality to WebSphere Portal

developerWorks
Document options

Document options requiring JavaScript are not displayed


Rate this page

Help us improve this content


Level: Introductory

Nicholas Chase, President, Chase and Chase, Inc.

01 Jun 2003

In their quest to create MetroSphere, a community weblog and information marketplace, the MetroSphere team is building the site using IBM WebSphere Portal, which is built on a collection of small applications called portlets. In this article, Nick Chase obtains a pre-written portlet application for request tracking and installs it on the portal.
Editor's update

The Web site MetroSphere.com -- the online technical community discussed in this article -- is no longer live. However, the information and screen captures regarding the installation of IBM WebSphere Portal are still accurate and relevant.

If you've been following along with this series, you already know that MetroSphere is a community weblog and information marketplace, where users can exchange information, carve out niches for themselves, and keep abreast of industry happenings. You probably also know that we're building MetroSphere on the IBM WebSphere Portal platform. In this article, we're going to start dealing with the base "unit" of a portal, the portlet.

So far, we've looked at the overall capabilities of the portal, we've discussed our business goals, and we've started gearing up for building onto portal by looking at JavaServer Pages technology. Now we're going to actually add some capabilities to the portal. In this article, we're going to obtain a pre-written portlet application that provides industry news and install it on the portal. No programming is required for this article, but if you want to follow along you're going to need a working WebSphere Portal on which you have administrative privileges.

Making a new portlet available for users involves obtaining the portlet application, installing it on the system, and adding it to user pages.

What is a portlet?

Before I go any further, it's probably a good idea to discuss portlets themselves, because everything we build on the system will be based on them.

The whole idea of a portal system is the ability to aggregate information from a number of different sources, in many cases on a single page. In order to accomplish this in a modular way, a portal typically involves the use of portlets, or small applications that "plug in" to the page. For example, the default home page for WebSphere Portal includes seven portlets, some of which are shown in Figure 1.


Figure 1. Portlets on the default portal home page
Portal home page

Each of these portlets, Welcome to WebSphere Portal, My News, My Stocks, My Weather, and Bookmarks is a separate application, installed and managed independently of the others. When a user requests the page, the server generates the content of each portlet (in no particular order) and then aggregates it all into a single page.

Portlets are based on the Portlet API, which means that any version of WebSphere Portal can use them. The same portlets that run on WebSphere Portal - Express can run on WebSphere Portal Enable, Extend, and so on.

Portlets can do anything a servlet can do, and more, thanks to their integration with the portal software itself. Eventually, we'll take the JSP pages that we built in Part 12: Hands-on intro to JSP technology: Creating a community weblog and incorporate them into a series of portlets that will make up the weblogging portlet application. We'll have one portlet that outputs the available topics, another to display the list of available entries, another for a calendar of available days, and so on.

But before we can get that far, we need to look at what's involved in installing a portlet application that already exists.

Which means we have to find one.



Back to top


The portlet catalog

One nice thing about using IBM WebSphere Portal is that there is no shortage of available portlets. The software itself comes with dozens of them, covering all sorts of tasks from viewing documents, to displaying your e-mail, to interacting with a Lotus Notes server.

In this case, I'm looking for portlets that don't come with Portal; specifically, I'm looking for industry news sources that I can make available to our users. So I headed off to the Portlet Catalog.

The Portlet Catalog, at http://www-3.ibm.com/software/webservers/portal/portlet/catalog, has a great number of portlets organized by a number of different criteria, such as application type, industry, and price, as shown in Figure 2.


Figure 2. Portlet information
Portal catalog info

In the "Free" category, I found the Hoovers Capsule Search. Clicking on it gives information about the offered portlet application and the company that produced it, and a link to download the application. In this case, the link goes to the Hoovers site, where I filled out some basic information and was directed to a page with several available portlet applications. I downloaded the Industry News portlet WAR file to get started.



Back to top


The WAR file

Portlet applications come packaged as WAR files, which you can then install directly onto the portal through the Portal Administration section without having to restart the portal to complete the installation.

WAR files are actually just specially constructed zip files with manifest information. For example, the Hoov_IN.war file, which includes the industry news portlets, has the following structure:


Listing 1. File structure
META_INF
  MANIFEST.MF
WEB_INF
  classes
    com
      ibm
        wps
          portlets
            ServletInvokerPortlet.class
    Dummy.class
  ibm-web-bnd.xmi
  ibm-web-ext.xmi
  portlet.xml
  web.xml

The web.xml file contains the same type of information it would in any J2EE application, identifying the servlet to the Web server:


Listing 2. The web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" 
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app id="WebApp">
    <display-name>Hoov_IN</display-name>
    <servlet id="Servlet_1">
        <servlet-name>ServletInvokerPortlet</servlet-name>
        <display-name>ServletInvokerPortlet</display-name>
        <servlet-class>com.ibm.wps.portlets.ServletInvokerPortlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>ServletInvokerPortlet</servlet-name>
        <url-pattern>/ServletInvokerPortlet/*</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
</web-app>

The portlet.xml file, on the other hand, has information that defines the actual portlet:


Listing 3. The portlet.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE portlet-app-def PUBLIC "-//IBM//DTD Portlet Application 1.1//EN" 
"portlet_1.1.dtd">
<portlet-app-def>
    <portlet-app uid="92b3e1c0-8ec6-1201-0000-00666c83a234:1" 
        major-version="1" minor-version="0">
        <portlet-app-name>Hoov_IN</portlet-app-name>
        <portlet id="Portlet_1" href="WEB-INF/web.xml#Servlet_1" 
              major-version="1" minor-version="0">
            <portlet-name>Industry News</portlet-name>
            <cache>
                <expires>0</expires>
                <shared>NO</shared>
            </cache>
            <allows>
                <maximized/>
                <minimized/>
            </allows>
            <supports>
                <markup name="html">
                     <view/>
                </markup>
            </supports>
        </portlet>
    </portlet-app>	
    <concrete-portlet-app uid="92b3e1c0-8ec6-1201-0000-00666c83a234:1.1">
        <portlet-app-name>Hoov_IN-Aerospace</portlet-app-name>
        <concrete-portlet href="#Portlet_1">
            <portlet-name>Hoov_IN-Aerospace</portlet-name>
            <default-locale>en</default-locale>
            <language locale="en">
                <title>Industry News - Aerospace and Defense</title>
                <title-short></title-short>
                <description>Industry News</description>
                <keywords></keywords>
            </language>
            <config-param>
                <param-name>url</param-name>
                <param-value>http://portlets.hoovers.com/portlets/
portlets.php?portlet=industry_news&partnerid=MetroSpherecom&parent=ibm&
auth=60dc25e23sdsd312424dd9fe05f713756d0f&part_info=Industry-Sector&output_
type=html&ind=Aerospace%2fDefense</param-value>
            </config-param>
        </concrete-portlet>
     </concrete-portlet-app>	
     <concrete-portlet-app uid="92b3e1c0-8ec6-1201-0000-00666c83a234:1.2">
        <portlet-app-name>Hoov_IN-Automotive</portlet-app-name>
        <concrete-portlet href="#Portlet_1">
            <portlet-name>Hoov_IN-Automotive</portlet-name>
            <default-locale>en</default-locale>
            <language locale="en">
                <title>Industry News - Automotive and Transport</title>
                <title-short></title-short>
                <description>Industry News</description>
                <keywords></keywords>
            </language>
            <config-param>
                <param-name>url</param-name>
                <param-value>http://portlets.hoovers.com/portlets/
portlets.php?portlet=industry_news&partnerid=MetroSpherecom&parent=ibm&
auth=60dc25e23sdsd312424dd9fe05f713756d0f&part_info=Industry-Sector&output_
type=html&ind=Automotive+@@amp@@+Transport</param-value>
            </config-param>
        </concrete-portlet>
    </concrete-portlet-app>
...
</portlet-app-def>

In this case, we have several "concrete portlet applications," or configurations, based on a single portlet. When you install the portlet application, Portal will use this information to store the portlet on the system and display information about it when needed.



Back to top


Installing the portlet application

Once you have the WAR file, actually installing the portlet application is fairly straightforward. First log into the portal itself with an account, such as wpsadmin, that has administrative privileges. Once you're logged in, select Portal Administration and click Install Portlets. Click Browse, select the WAR file to install, and then click Next.


Figure 3. Choose the WAR file
Choose the WAR file

The portal displays all of the portlets that are part of the application within the WAR file. In many cases there is just a single portlet, but in other cases, such as this one, multiple portlets are packaged together, as shown in Figure 4.


Figure 4. The available portlets
The available portlets

After confirming that these are the portlets you want to install, click the Install button. If all is well, the portlet will give you a message saying "Portlets successfully installed." If, on the other hand, there was a problem with the installation, you can find information on why in the log file located at <WebSphere home>/PortalServer/log/appserver-err.log.

Once the portlet (or in this case, portlets) has been installed, we'll need to add it to the page before anyone can actually use it.



Back to top


Adding the portlet to the page

WebSphere Portal is designed to make it easy to modify the layout of a page, particularly when it comes to the portlets that appear on any given page. While you're logged in as a portal administrator, choose Work With Pages and click the Edit My Pages tab. Click Edit Page Composition and pick the appropriate page. Just to get started, I'm going to add them to the My Portlets page of the Welcome section, or "place".

To make the new portlets available for adding to the page, choose a row or column "container" and click the Add Content... button, as shown in Figure 5.


Figure 5. Add content
Adding content

On the next page, make sure All Available portlets is selected and click Search. At the bottom of the page, all of the available portlets will appear, as shown in Figure 6.


Figure 6. Showing all portlets
Showing all portlets

In order to actually add the portlet to the page, pick the portlets you want by clicking the checkbox next to them. In our case, we chose the Hoov_IN - Media and Hoov_IN - Computer Software portlets. Once you've added all the necessary portlets to the list, click the OK link to go back to the page layout. The portlets will be automatically added to the appropriate container, as shown in Figure 7. (For more information on controlling the layout of a page, see Part 7: Customizing pages with WebSphere Portal - Express.)


Figure 7. Adding the portlet
Adding the portlet

When you add the portlet, it starts at the end of the row or the bottom of the column, as shown in Figure 7. You can move it around on the page, either up and down within a column or even between columns, by using the arrows next to the portlet name.


Figure 7. The results
The results

Don't forget that changes will show on the live page immediately, even if you don't click Done. (In earlier versions of Portal, you need to click Activate ... to put the page back in action.)



Back to top


Uninstalling the portlet

No discussion on installation would be complete without a quick word on uninstalling. In the case of a portlet application, it's pretty straightforward. To uninstall the new application, choose Portal Administration and click Portlet Applications. Select the appropriate application -- such as Hoov_IN, in this case -- and click the Uninstall link.

Uninstalling a portlet application automatically removes the portlet instances from any pages to which you've added them.



Back to top


Summary

Adding portlets to the portal system is crucial to all of our development. Later we'll be writing new portlets, but for now, we've obtained industry news portlets from the IBM Portlet Catalog. To make use of them, we used the Portlet Adminstration section to install the portlets within the WAR file, then used the Work with Pages section to add portlet instances to an actual page. Later, our users will be able to add these portlets to their own pages.



Resources



About the author

Nicholas Chase

Nicholas Chase, a Studio B author, has been involved in Web site development for companies such as Lucent Technologies, Sun Microsystems, Oracle, and the Tampa Bay Buccaneers. Nick has been a high school physics teacher, a low-level radioactive waste facility manager, an online science fiction magazine editor, a multimedia engineer, and an Oracle instructor. More recently, he was the Chief Technology Officer of Site Dynamics Interactive Communications in Clearwater, Florida, and is the author of four books on Web development, including XML Primer Plus (Sams).




Rate this page


Please take a moment to complete this form to help us better serve you.



YesNoDon't know
 


 


12345
Not
useful
Extremely
useful
 


Back to top