Datasheet

Patrick c01.tex V3 - 09/18/2009 12:15pm Page 21
Chapter 1: Building Web Applications in WebLogic
Best Practice
The JSP 2.0 tag files mechanism provides a new approach for sharing and including JSP
pages and page fragments that might make sense if the older
<jsp:include>
action and
<%@include file="..." %>
directive do not meet your needs. Be sure there is sufficient
value in changing to the new approach since it represents additional complexity.
Custom Tag Use Is Easy Development Is Complex
It is important to keep the appropriate goal firmly in mind when evaluating a new technology or feature
for potential use on your project. In the case of technologies such as custom tags, the goal is to improve
the readability and maintainability of the JSP pages. The assumption is that by reducing or eliminating
scriptlet code the page will be easier to understand and maintain, which is true enough, but the JSP pages
are only one part of the total system being developed. The beans and custom tags are part of the system as
well, and any improvement in maintainability of the JSP pages must be weighed against the complexity
and maintenance requirements of the beans and tags themselves.
Custom tag development, in particular, is complex. The complexity is not evident until the tasks being
performed become more realistic, perhaps requiring TEI classes, body content manipulation, handling
of nested tags, or other more advanced behaviors. Examine the source code for some tag libraries avail-
able in the open source community to get a sense of the requirements for a realistic, production-ready
tag library. Is your development team ready to tackle this level of development? Are the people being
earmarked for maintenance of the application capable of maintaining, extending, or debugging problems
in the tag library? These are valid questions you should consider when making your decision to build a
custom tag library.
Using custom tags, on the other hand, is relatively easy. As you saw in the discussion of the JSTL libraries,
it requires a simple declaration at the top of the JSP page and a few straightforward XML elements in the
page to invoke a custom tag and produce the desired behavior.
In the end, the decision comes down to the benefits of using custom tags versus the effort to develop
and maintain the custom tags. Clearly a tag that is developed once and used on many pages may pay for
itself through the incremental benefits accrued across multiple uses. Taken to the limit, the most benefit
will come from a tag used in many pages that is acquired rather than internally developed, eliminating
all development and maintenance effort on the tag itself. This should be your goal: Use custom tags, but
don’t develop them.
Best Practice
Custom tags are easy to use but difficult to develop and maintain, so make every effort
to locate and use existing tag libraries from reputable sources rather than developing
your own custom tags.
21