ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

What Is a Portlet, Part 2

by Sunil Patil
"Portlets are web components--like servlets--specifically designed to be aggregated in the context of a composite page. Usually, many portlets are invoked to in the single request of a portal page. Each portlet produces a fragment of markup that is combined with the markup of other portlets, all within the portal page markup." (from the Portlet Specification, JSR 168)

In this Article:

  1. Using the Admin Console
  2. Adding Support for Edit Mode
  3. Using JSP to Display Help
  4. Portlet Request Processing
  5. Greet User with Personalized Message
  6. The Portlet Tag Library
  7. Portlet Preferences
  8. Caching
  9. Conclusion
  10. Resources

In "What is a Portlet," we started by talking about Portlet basics such as what portlets and portals are, how to create a simple portlet, and how to deploy it on the JSR 168 reference implementation, Pluto. This article talks about advanced Portlet topics by building on discussion in that article.

We will start our discussion with how to enable other portlet modes, such as EDIT and HELP, in the HelloWorld portlet. Then we will talk about how to use JSPs to generate markup. Next, we will discuss how portlet request processing works, in addition to how portlets make action processing easy for us. One of the new things in the Portlet specification is the concept of PortletPreferences, which allows the user to customize the view or behavior by storing configuration data as name-value pairs.

But let's begin by talking about the new admin console, which provides a UI for performing common administrative tasks.

Using the Admin Console

The good news on the Pluto side is now it has an admin console, which takes much of the pain out of Pluto administration. To use the console, download any version of Pluto after RC-3 and install it on your machine. Newer versions of Pluto are based on Tomcat 5.5, which requires J2SE 5.0.

If you don't want to install J2SE 5.0, you can try a hack that worked for me. Begin by shutting down your Pluto server. Extract the new Pluto version (rc4, in this example) to a folder such as c:\temp, and then go to its webapps folder (i.e., c:\temp\pluto-1.0.1-rc4\webapps). Copy the pluto folder from here and paste it into your pluto-1.0.1-rc1\webapps folder. It will ask if you want to overwrite; say "yes." Then start your rc1 server; this should show you a link to admin console in the panel on the left side.

Figure 1 shows what your browser will look like when you access an admin console.

Thumbnail, click for full-size image.
Figure 1. Admin console (click for full-size image)

In the first installment, we discussed pageregistry.xml and portletentityregistry.xml, and how Pluto looks at these files to find out how a particular page should be displayed. The basics remain same in the newer versions of Pluto--configuration information is still stored in these files. The difference is that you don't have to edit these files manually any more. Instead you can use admin console portlets to changes these files. Click on the Admin link in the left panel to open Pluto's admin console, which has the following three portlets:

  1. Deploy War Admin Portlet: This is the main (and only interactive) portlet in the admin console. It allows you to either install a new portlet or update existing portlet. It will modify configuration files such as portletentityregistry.xml, pageregistry.xml, and portletcontexts.txt.
  2. Portlet Entity Registry: This non-interactive portlet displays content in the portletentityregistry.xml file.
  3. Page Registry: This non-interactive portlet is a view of data contained in the pageregistry.xml file.

The admin console can be used either for installing new portlets or updating existing portlets. First, we will talk about how to use the admin console to install HelloWorld.war. Inside Deploy War Admin Portlet, click Browse, choose the HelloWorld.war file, and click Submit. This will deploy the HelloWorld portlet to Pluto. Specifically, this means Pluto will unzip the HelloWorld.war file in the webapps directory, and add entries to the portletentityregirstry.xml and porteltcontexts.txt files. You will see these changes reflected in the Portlet Entity Registry Admin portlet.

On the next screen, Pluto will ask you about layout information for the HelloWorld portlet. In the title field, you should specify name of the link (i.e., "Hello World") that will appear on the left-hand side, along with the number of rows and columns needed to display all portlets in the application. In the HelloWorld.war application, we have only one portlet, so we will keep default values of one row and one column. Click on Submit to make these changes and go to the Page Layout page, where you can choose which portlet is to be displayed in which row or column. Once you click submit this form, this will make an entry in the pageregistry.xml file. Our sample application has only one portlet, which will be selected by default, so all we have to do is click Submit. Now restart Pluto to get see the new link on the left-hand side.

If you want to re-deploy the HelloWorld portlet, go to the Deploy War Admin portlet, click Browse, and choose HelloWorld.war. When you click Submit, it will update the existing application, and on the next page it will show you a message saying you are trying to update an existing portlet. You should skip the subsequent pages, because when you're updating an existing portlet, no changes need to be made to portletentityregistry.xml and pagecontexts.txt (i.e., configuration files).

Head First Servlets and JSP

Related Reading

Head First Servlets and JSP
Passing the Sun Certified Web Component Developer Exam
By Bryan Basham, Kathy Sierra, Bert Bates

Pages: 1, 2, 3, 4, 5

Next Pagearrow