Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

The Making of MetroSphere, Part 15: Making tag libraries available throughout the portal

Use a custom tag library from outside a portlet application

Nicholas Chase, President, Chase and Chase, Inc.
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 an interactive development firm in Clearwater, Florida, and is the author of four books on Web development, including XML Primer Plus (Sams).

Summary:  Adding functionality such as JSP tag libraries to a portlet application is easy: simply include the appropriate files when creating the WAR file. But what if you need to use that tag library outside the portlet application? This tip follows the addition of the blogutil tag library to the MetroSphere portal's registration page.

Date:  01 Jul 2003
Level:  Introductory

Activity:  2619 views
Comments:  

You'll need to have a working installation of IBM WebSphere Portal Server Version 4.x to follow along with this tip.

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.

What we want to accomplish

The MetroSphere portal is a community weblog aimed at technology professionals, and one of our team's major goals is the personalization of content. As such, it's important that we know what categories of information a particular user would like to see. Although the personalization engine that comes with portal provides all kinds of sophisticated ways to figure that out through tracking and comparing a user's actions to those of other users, there is one very simple way for us to know what topics interest a user.

We can ask.

To do that, we're going to add a list of topics to the registration page, as in Figure 1.


Figure 1. The completed page
The completed page

This list is only temporary, of course. As we get closer to completion, we'll refine it further, so it's natural to pull the topics from a database. And because this is just one of many places in which we're displaying a list of topics, it makes sense to use a tag library to do it.


Adding the tag library to the page

The body of the registration page is contained in the file:

<WebSphere Home>/PortalServer/app/wps.ear/wps.war/screens/html/UserProfileForm.jsp

In addition to changing the layout of the page slightly, we added a reference to the tag library and the tags themselves:


Listing 1. Adding the tags to the page
<%@ page session="false" buffer="none" %>
<%-- Licensed Materials - Property of IBM, 5724-B88, (C) Copyright IBM Corp. 2001, 2002 - 
All Rights reserved. --%>
 
<%@ taglib uri="/WEB-INF/tld/engine.tld" prefix="wps" %>
<%@ taglib uri="/WEB-INF/tld/blogtaglib.tld" prefix="blogutil" %>
<%@ include file="BidiInclude.jsp" %>

<wps:constants />

<jsp:useBean id="userWrapper" class="com.ibm.wps.puma.UserWrapper" scope="request"/>
<jsp:useBean id="errorBean"  class="com.ibm.wps.puma.UserState" scope="request"/>
<jsp:useBean id="reqAttributes" class="java.util.Vector" scope="request" />

<%@ page import="com.ibm.wps.datastore.LanguageDescriptor" %>
...
                 </td><td style="background-color: #ECECEC" valign="top">
<table>
   <tr><td colspan="3">&nbsp;</td></tr>
   <tr>
       <td align="<%= bidiAlignRight %>"><%=  
           reqAttributes.contains("FAVORITETOPICS")?"*":" &nbsp;&nbsp;" %></td>
       <td align="<%= bidiAlignLeft %>" class="wpsEditText">
           <b><label for="wps.FavoriteTopics"><wps:text key="metro.favTopics" 
                     bundle="nls.metro">Preferred Topics</wps:text></label></b>
       </td>
   </tr>
<blogutil:topiclist selected="-1">
   <jsp:useBean id="topicelement" class="com.metrosphere.util.TopicBean" />
   <tr>
       <td><input type="checkbox" name="topicChoice" 
          value="<jsp:getProperty name="topicelement" property="topicId" />"/>
       </td>
       <td><jsp:getProperty name="topicelement" property="topicName" /></td>
       <td>&nbsp;</td>
   </tr>
</blogutil:topiclist>
</table>

</td></tr>
</table>
<span class ="wpsEditSmText" ><wps:text key="requiredfield" 
   bundle="nls.registration" /></span>
              </td></tr>
        </td>
    </tr>
    </table>
  
<%-- start admin footer --%>
<table cellspacing="4" cellpadding="0" border="0" width="100%">
...
			

In an upcoming article on using custom user attributes, we'll look at making sure that checkboxes are preselected if the user is editing his or her profile rather than creating a new one, but for now we're just thinking about getting the tag library in place. Ultimately, we'll also have to add the topics tags to the UserProfileConf.jsp page.


Adding the classes and tag library file

For any of this to work, we need to make sure that the tag classes are available to the portal itself. When we were using the tags within a portlet application, we didn't have to worry about it; we simply included the classes in the application. Now we need to make the classes available to the portal itself.

When using J2EE, there are typically two ways to make a class available to the application. The first, and most convenient, is to take the relevant class files and add them to a JAR file, and then add the JAR file to the /WEB-INF/lib directory. In some cases, however, including some versions of WebSphere Application Server included with WebSphere Portal, these JAR files are not automatically added to the classpath, so you need to add the individual classes to the /WEB-INF/classes directory of the overall application server, taking into account the package hierarchy:

<WebSphere Home>/AppServer/classes/com/metrosphere/util/BlogConnection.class
<WebSphere Home>/AppServer/classes/com/metrosphere/util/TopicBean.class
<WebSphere Home>/AppServer/classes/com/metrosphere/util/TopicListTag.class
<WebSphere Home>/AppServer/classes/com/metrosphere/util/TopicTag.class

We also need to make the tag library definition file, blogtaglib.tld, available to the portal application. The trick is in understanding that what we think of as the "portal" itself is actually a J2EE application in the PortalServer directory. So in order to add the blog utility classes to the overall portal, we need to add the .tld file to the following directory:

<WebSphere Home>/PortalServer/app/wps.ear/wps.war/WEB-INF/tld/

This is the directory referenced by the page directive:

<%@ taglib uri="/WEB-INF/tld/blogtaglib.tld" prefix="blogutil" %>

You can also use the web.xml file to specify aliases for this tag library.


Using the web.xml file

In some cases, you may want to create an alias for the tag library by adding it to the web.xml file. This file is located in:

<WebSphere Home>/PortalServer/app/wps.ear/wps.war/WEB-INF/tld/

To add the tag library to the file, you can simply add a taglib element:


Listing 1. Adding an alias to the web.xml file.
...
    <servlet-mapping id="ServletMapping_tr_3">
        <servlet-name>TranscodingUtilities</servlet-name>
        <url-pattern>/TranscodingUtilities/*</url-pattern>
    </servlet-mapping>
    <taglib>
        <taglib-uri>/WEB-INF/tld/blogtaglib.tld</taglib-uri>
        <taglib-location>/WEB-INF/tld/blogtaglib.tld </taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>engine</taglib-uri>
        <taglib-location>WEB-INF/tld/engine.tld</taglib-location>
    </taglib>
...

One reason to do this is for mantainability. You can create an alias for the file, and then if you decide to change it later, say, to create a new version, you won't have to alter any of the actual JSP files. Instead, you can just make one change to the web.xml file.


Summary

By making the topic list tag library available to the portal, you can greatly increase maintainability for pages that are not part of a portlet application. To do that, you add the classes to the classes directory of the application server itself, and the tag library definition to the WEB-INF/tld directory within the PortalServer directory.


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 an interactive development firm in Clearwater, Florida, and is the author of four books on Web development, including XML Primer Plus (Sams).

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Sample IT projects
ArticleID=10274
ArticleTitle=The Making of MetroSphere, Part 15: Making tag libraries available throughout the portal
publish-date=07012003
author1-email=
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).