Articles
Index
The Jakarta Taglibs
Project--Part I
By Steve
Meloan
April 2001
The JavaServer PagesTM
(JSPTM) 1.1 specification
allows JSP developers to create their own action tags--to
provide custom functionality that is invoked by a defined set
of HTML-like tags. Custom tag libraries provide developers
with the ability to distill down complex server-side behaviors
into simple and easy to use elements that content developers
can then incorporate into their JSP pages.
This article, the first of two parts, explores the Jakarta
Taglibs Project (part of the not-for-profit Apache Software
Foundation), which provides a wide array of open-source custom
tag libraries for use in JavaServer Pages. First, a brief
review of the concept of custom tag libraries is offered,
followed by an overview of the workings of the Jakarta Taglibs
Project and its various custom tag libraries, and concluding
with the open-source development experiences of several
members of the Jakarta community.
Part II of this article will explore several recently
released Jakarta taglibs, as well as one that is currently in
development, and offer sample code that uses these new
libraries.
| "Custom tag
libraries encourage a clean division of labor between
library developers and library users, greatly reducing,
or even eliminating, the need to embed Java code
directly in JSP pages."
|
A Review of Custom JSP Tags
Using a custom tag library within a JSP page is relatively
simple. The taglib directive is used to import
the custom tag library into the JSP.
<%@ taglib uri="TagLibraryURI" prefix="tagPrefix" %>
The uri attribute takes a Uniform Resource
Identifier (URI) that specifies the location of the tag
library descriptor (TLD). This can be a relative or absolute
URI.
The prefix is a unique specifier used to
qualify the custom tags that are part of a particular tag
library.
<%@ taglib
uri="WEB-INF/mytaglib.tld" prefix="mytags" %>
Given the above taglib directive, the JSP
container will look for mytaglib.tld in a
directory named WEB-INF off the root of the web
application. The prefix "mytags" is then used
when including a tag from that library in a given JSP:
<mytags:tag1 />
Custom tag libraries encourage a clean division of labor
between library developers and library users, greatly
reducing, or even eliminating, the need to embed Java code
directly in JSP pages. Tag libraries are created by
developers, who are proficient with the Java programming
language, and expert at accessing data and system services.
Tag libraries are used by web content designers, who can then
better focus on presentation issues. Custom tags accomplish
some of the same goals as JavaBeans that are used within a
JSP. But they have numerous other advantages.
Custom tag features:
<mytags:outerTag>
<mytags:innerTag
/>
</mytags:outerTag>
On the custom tag library developer end, tag actions
are defined using tag handlers. Tag handlers are server side
objects used at runtime to evaluate and effect the intended
actions of the custom tags. A tag handler must implement one
of two interfaces--Tag or BodyTag,
depending on whether the given tag needs to manipulate body
content or not. TagSupport and
BodyTagSupport implement Tag, and
can be used as base classes when creating tag handlers.
Meanwhile, a tag library description (TLD), written in XML,
is used to describe the composition of a given tag library.
This information includes detail on the individual tags and
mappings to their tag handlers, version information on the JSP
container, the tag library, and so on.
|
"The Jakarta Project operates on a
meritocracy--the more you do, the more responsibility
you will obtain. As a result, there is room for
contribution within this open-source development effort
at a variety of different levels."
|
Jakarta Taglibs Project
The goal of the Jakarta Project is to provide
commercial-quality server solutions based on the Java platform
that are developed in an open and cooperative fashion.
Jakarta, part of the not-for-profit Apache Software
Foundation, is the overall project name that encompasses many
different subprojects. Tomcat is the Servlet + JSP Engine that
is a subproject of the greater Jakarta Project. Another
Jakarta subproject is Jakarta Taglibs.
Sun Microsystems licensed its JavaServer Pages technology
to the Apache developer community in June of 1999. Since then,
a burgeoning JSP development community has taken hold at
Jakarta. The Jakarta Project operates on a meritocracy--the
more you do, the more responsibility you will obtain. As a
result, there is room for contribution within this open-source
development effort at a variety of different levels.
Jakarta users are those who simply use the products
of the Project. They aren't necessarily contributing code, but
they are using the products, reporting bugs, making feature
requests, and so on. In many ways, these are the most
important members of the project. It is with this feedback
that the products grow and evolve. When users begin to
contribute code, they become developers. Developers are
those that write code or document patches, or contribute
positively to the project in other ways.
Developers who provide frequent and valuable contributions
to a Jakarta subproject can be promoted to the status of
committer. A committer has write access to the source
code repository, and gains voting rights that allow him or her
to effect the future of the subproject. Developers can either
be nominated for committer status by another committer, or
nominate themselves. At that point, the other committers of
the subproject will vote on the proposal. If there are at
least three positive votes, and no negative votes, then the
developer is promoted to the status of committer, and given
write access to the source code repository for that
subproject.
Finally, committers who regularly participate and make
valuable contributions may have their status promoted to
project manager committee member. The Project
Management Committee (PMC) is the official managing body of
the Jakarta Project, and is responsible for setting overall
project direction. To become a member, a current PMC member
must nominate the committer, and he or she must be approved by
a 75% majority of the PMC.
The Jakarta Project obtains its strength and usefulness via
the ongoing communication and interaction between its members.
The Taglib Project has several email lists for this
purpose.
The Jakarta Taglibs user mailing list is used to
send questions and comments about configuration, setup, usage,
and other user types of questions. The Jakarta Taglibs
developer mailing list is used to send questions and
comments about the actual software source code, and general
development types of questions.
All developers are encouraged to participate and offer
suggestions, but the ultimate decision is made by those that
have committer status. Any developer may also vote on an issue
or action item, but the only binding votes are those made by
committers. Meanwhile, the act of voting carries
responsibilities. Voting members are not only stating an
opinion, they are agreeing to help do the work. Each committer
vote can be cast in one of four flavors:
- +1 - Agree, the action should be performed.
- +0 - Agree, but I don't have the time, inclination, or
skill to work on it.
- -0 - Abstain with a bullet. I'm against it, but I'm not
voting against it.
- -1 - I'm against it. (Note: All such veto votes must
contain an explanation of the decision.)
An action requiring consensus approval must receive at
least three binding +1 votes, and no binding vetoes. An action
requiring majority approval must receive at least three
binding +1 votes, and more +1 votes than -1 votes.
Jakarta Taglibs
- Application Taglib
The Application custom tag library
contains tags that can be used to access information
contained in the ServletContext for a web
application.
- BSF Taglib
The Bean Scripting Framework (BSF) is an
architecture for incorporating scripting into Java
applications and applets.
- DateTime Taglib
The DateTime custom tag library
contains tags that can be used to handle date and time
related functions.
- Input Taglib
The Input tag library lets you present
HTML elements that are tied to the
ServletRequest that caused the current JSP page
to run. That is, using this library, you can easily
prepopulate form elements with prior values that the user
has chosen.
- JDBC Taglib
The JDBC custom tag library contains tags
that can be used to read from and write to an SQL database.
- JNDI Taglib
The JNDI tag library creates an instance
of a javax.naming.Context based on the values
of the attributes providing some of the standard values.
- JSP Spec Taglib
The JSP Spec custom tag library
contains working examples of the tags described in the
JavaServerPages specification, version 1.1. As such, the
tags are focused more on being examples of custom tag
library code techniques, and less on being useful in
production applications.
- Page Taglib
The Page custom tag library contains tags
that can be used to access all the information about the
PageContext for a JSP page. Tags are provided
to access information in "page"-scoped attributes.
- Regexp Taglib
The Regexp custom tag library contains
tags that can be used to perform Perl syntax regular
expressions.
- Request Taglib
The Request custom tag library
contains tags that can be used to access all the information
about the HTTP request for a JSP page. Tags are provided to
access information in the HTTP request for HTTP input
parameters from a POST or GET, HTTP Headers, cookies,
request attributes, and session information related to this
request.
- Response Taglib
The Response custom tag library
contains tags that can be used to set all the information
for an HTTP response for a JSP page. This includes creating
cookies and setting their values, setting HTTP headers,
returning an HTTP error, or sending an HTTP redirect.
- Scrape Taglib
The Scrape tag library can extract, or
"scrape," content from web documents, and display that
content in a JSP. Stock quotes, for example, can be scraped
from one web site, and then displayed in a JSP page.
- Session Taglib
The Session JSP tag library provides
tags for reading or modifying client HttpSession
information. A servlet container uses an HttpSession to
store information about a client's session on the server. By
default, a JSP page creates a session for a user. The user
is tied to the session using either a cookie, or by using
URL rewriting. This is how information is tied to a user
between multiple HTTP requests to the server.
| "Contributing
to the project doesn't involve a steep learning curve,
as is often the case with other more complex
projects," says Sun's Pierre Delisle. "Just think of a
cool idea for a tag library, and the community will be
happy to see you contribute it to the
project." |
- SQL Taglib
The SQL Tag Library is an implementation
of the SQL tags discussed in Section A.2.1 and A.2.2 of the
JSP Pages 1.1 Specification.
- Utility Taglib
The Utility custom tag-library
contains examples of some basic tags. It illustrates several
custom tag library code techniques.
- XSL Taglib
The XSL custom tag library contains
working examples of the tags described in the JSP 1.1
specification. As such, the tags are focused more on being
examples of custom tag library code techniques, and less on
being useful in production applications. With this custom
tag library, users can process an XML document with an XSL
stylesheet, and insert it in place.
Recent Jakarta Taglibs
The Jakarta Taglibs Project has recently released several
new taglibs--JDBC and Scrape, with another one, Tag
Pipelining, currently in the development stages. Part II of
this series, will explore those taglibs in greater technical
depth.
The Jakarta members involved in the JDBC, Scrape, and Tag
Pipelining libraries came to Jakarta through different paths.
But the story of each illustrates the strength of both custom
JSP tag libraries, and the Jakarta open-source development
process.
How to Get Started with Jakarta
TaglibJakarta-Taglibs is available
in both binary and source distributions. In general, the
binaries are meant for developers who simply want to use
the technology (as opposed to those that might want to
alter the code in order to integrate it into other
products).
Binary
Distribution
Source
Distribution
Documentation
The Jakarta Project's codebase is maintained in
shared information repositories using CVS. Only
committers have write access to these repositories, but
everyone has read access via anonymous CVS.
The
Jakarta Taglibs user mailing list
The
Jakarta Taglibs developer mailing
list
To
report a bug, or request a feature
enhancement
When filling out a bug report or feature request, the
Jakarta Project recommends the following:
- Select Taglibs from the product list
- Include the tag library where the problem exists
- Provide the details of your operating environment
- Provide an explanation of the problem
- Provide a way to reproduce the problem, if
possible
- Provide any other information that may be
pertinent
While the documentation for each Jakarta tag library
indicates its committers, most communications regarding
a given library should be directed to the community as a
whole. However, individual members can be contacted via
postings found in the email archive.
Jakarta Taglibs: Dev
Email Archive
Jakarta Taglibs: User
Email
Archive |
"The Jakarta taglibs project is a great way to get involved
with open-source," says Pierre Delisle, Staff Engineer for Sun
Microsystems. Delisle is a committer for several Jakarta
taglibs, and is currently working on the concept of "tag
pipelining" with James Strachan, a consultant at Metastuff
Ltd. out of London, England. The goal of tag pipelining is to
allow the output of one JSP custom tag to transparently serve
as the input for another tag--in the classic sense of pipes in
the UNIX platform.
One advantage of the Jakarta taglibs is that each tag
library is its own well-defined mini-project. "The cost of
entry into the open-source world within this context is
minimal," says Delisle. "Contributing to the project doesn't
involve a steep learning curve, as is often the case with
other more complex projects. Just think of a cool idea for a
tag library, and the community will be happy to see you
contribute it to the project."
Morgan Delagrange is a Senior Systems Architect for
Britannica.com. But he also maintains his own web site, which
is used to trade DVDs and computer games with friends. He was
initially won over to the Java programming language's approach
to structured programming. From there, he became fascinated by
servlets and JavaServer Pages, which he found far superior to
the templating language he had previously used with Perl. But
it was the feature-set of Tomcat that led Delagrange to the
Jakarta Project. "Tomcat is just so easy to use and install
compared to a lot of the other J2EETM engines out there," he says. "And
it has nice features like automatic class reloading."
Delagrange slowly worked his way up within the Jakarta
Project in terms of involvement and responsibility. He had
been writing scriptlets and JavaBeans to display and update
the data on his site. But it increasingly seemed that a set of
custom tags would better serve his needs. "I began exploring
custom tag library authoring," he says, "and in less than a
week I was able to learn the syntax and complete a set of tags
that met my needs." He eventually settled on a simplified
abstraction of the JDBCTM API.
"My JSPs were transformed as a result," he says. "Adding new
database features to the site became almost trivial.
From here, Delagrange began to explore the Jakarta Taglibs
Project. "I was struck by the Request and Session tag
libraries," he says. "But I noticed that the tags addressed
only two of the major servlet scopes, while the other two,
Page and Application, had no tag libraries." Delagrange
decided to create Page and Application tag libraries for use
in his own applications, but he also submitted them to the
Taglibs Project. This led to his being nominated for committer
status. "I was nominated by the original author of the Request
and Session tag libraries," he says. "Then I was accepted by
vote of the other committers."
| "I can't
overemphasize how much my custom tag library improved
through the discussions and contributions of the Taglib
Project," says Morgan Delagrange. "I think that
open-source development sparks a kind of creativity that
other techniques cannot match."
|
At this point, Delagrange submitted his JDBC tag library to
the project. And here, he has awarded particularly high marks
for the Jakarta Project's open-source development paradigm.
"Even though it was a useful tag library to begin with," he
says, "I can't overemphasize how much it improved through the
discussions and contributions of the Taglib Project. Features
that were a direct result of the discussions, debates, and
inspirations at Jakarta include: JNDI support, DataSource
support, PreparedStatement support, SQL-escaping tags, various
conditional logic tags (for dealing with nulls and empty
ResultSets and so on.), internationalization of time and
number formats, and more." While three other developers, Glenn
Nielsen, Rich Catlett, and Marius Scurtescu, directly
contributed to the code, well over a dozen people contributed
comments and criticisms to the JDBC tag library. "I think that
open-source development sparks a kind of creativity that other
techniques cannot match," says Delagrange. "When code is
subjected to a great deal of peer review, it just tends to be
more comprehensive."
Another recently released Jakarta taglib is Scrape, which,
as its name implies, provides tags useful in extracting
content from web documents, and displaying them in JSPs. Stock
quotes, for example, can be extracted from a financial site,
and then displayed within a user JSP.
The Scrape taglib's two committers are Glenn Nielsen, UNIX
Programming Coordinator for the Missouri Research and
Education Network (MOREnet), and Rich Catlett, a part-time
student programmer for MOREnet, and recent graduate of the
University of Missouri.
"MOREnet is part of the University of Missouri system,"
says Nielsen, "and acts as the ISP for the state of Missouri,
for K-12 schools, colleges, libraries, and state agencies. We
administer Internet servers that provide a wide range of
services. Some of that is web hosting." As a result, MOREnet
had begun to explore better ways of allowing its customers to
publish dynamic content. "We need to target a wide variety of
skill levels," says Nielsen. "And we saw JSPs as the way that
we could most easily push out the ability to do dynamic
content to our customers."
Like most members of the Jakarta Taglibs Project, Nielsen
came to Jakarta via a serendipitous path. "Last spring, when
we were looking at servlet containers," he says, "we looked at
four or five of them. But none of them had a means by which to
implement security." After speaking to a number of vendors,
Nielsen found security rather low on their list of
priorities.
Then, at ApacheCon, he spoke to several Jakarta Tomcat
developers. "They had already identified security as something
that they wanted to implement," says Nielsen. "So ultimately,
I ended up implementing the security manager for Tomcat."
From there, Nielsen began exploring tag libraries. This was
in the spring of 2000, not long after the custom tag library
spec was released. As a result, there were not many taglibs to
choose from. Meanwhile, Nielsen began exploring various
turnkey applications for MOREnet customers, among them, an
open-source message board that used JSPs, but with the Java
code embedded as scriptlets. "I realized around that time,"
says Nielsen, "that it would be nice to have some fundamental
tag libraries that you could build on top of. That's when I
wrote and contributed to the Request, Response, and Session
tag libraries." As a result of that work, Nielsen next began
to look toward offering a tag library directed at extracting
information from other sites. Together, Nielsen and Catlett
set about developing the Scrape tag library. "I did a lot of
the actual development work on it," says Catlett, "but Glenn
provided the broad overview and general direction to the
work."
And here again, there are high marks awarded to the Jakarta
open-source development paradigm. "I think it works very
well," says Nielsen, "because you can get a broad range of
perspectives and techniques for--not only how to structure the
attributes in your tags, for the people who will be using
them--but how to design the actual Java code. So you end up
with the interfaces to the tags that the user sees, and
the underlying code, being a great deal better because of the
interaction between the different developers."
"When you're developing something," adds Catlett, "you
can't possibly think of every need or use that might arise.
But in open-source, the code's out there being actively
discussed by a broad range of developers."
The Scrape library offers a great deal of power and
elegance within a relatively small tag set. It employs an
internal cache such that users don't have to constantly go to
the remote site in order to gather data. Depending upon the
update interval that's been specified (a background thread),
the taglib can decide whether it needs to reaccess the site,
or whether it can simply use its cached data. "I think the
Scrape library really shows how you can have a very simple
interface for the web publisher to use," says Nielsen, "but
that hides very complex operations behind it."
The various taglib developers at Jakarta often also end up
cross-pollinating with one another across libraries. "When
Morgan Delagrange was working on his JDBC library," says
Nielsen, "we had the idea to add the ability to use a JNDI
named data source. We suggested that on the developer list,
and convinced Morgan that it was a good idea. And he decided
that, since it was something we were already working with,
that it would be better if we just implemented it."
The Future
The Jakarta Taglibs Project is currently in a growth phase,
transitioning from the informal infrastructure of a technology
incubator, to the more mature update and release procedures
found in larger Jakarta projects. "When we release a tag
library, we currently just post a link on the home page and
send notification to the user mailing list," says Delagrange.
"Unlike some of the other projects on Jakarta, we don't have
stable releases yet. It's basically just daily builds. We make
a very strong effort to be sure those builds are good, in
terms of rigorous testing," he says, "but we don't have formal
unit testing, and we don't have a formal release process. As a
result, we're in active discussion on the list now as to how
to best do that."
In order to meet the challenges inherent in this more
mature phase, however, the project needs to continue to
attract new participants. "We're looking for more volunteers
to participate, with even greater involvement," says Delisle.
"We need everyone in the community to help move the Taglibs
project to the next level, where it will serve as a mature
development and distribution center for commercial-quality
open source JSP tag libraries."
Useful Links
The Jakarta
Taglibs Project
Jakarta
Taglibs Tutorial
Sun's
Tag Libraries Tutorial
Sun's
JSP Tag Library Site
JSP
1.1 Specification
Additional Information on JSP
Tag Libraries
About the Author
Steve Meloan, frequent
contributor to the JDC, and java.sun.com, is a journalist, and
former software developer. His work has appeared in Wired,
Rolling Stone, BUZZ, San Francisco Examiner, ZDTV's "The
Site," and American Cybercast's "The Pyramid."
Reader Feedback
Tell us what you think of this article.