Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
324
Chapter 14 Creating Custom JSP Tag Libraries
In this section, we see how to define tags that use their body content, and
are thus used in the following manner:
body
The Tag Handler Class
In the previous examples, the tag handlers defined a 
doStartTag
 method
that returned 
SKIP_BODY
. To instruct the system to make use of the body that
occurs between the new element's start and end tags, your 
doStartTag
method should return 
EVAL_BODY_INCLUDE
 instead. The body content can
contain JSP scripting elements, directives, and actions, just like the rest of the
page. The JSP constructs are translated into servlet code at page translation
time, and that code is invoked at request time.
If you make use of a tag body, then you might want to take some action
after the body as well as before it. Use the 
doEndTag
 method to specify this
action. In almost all cases, you want to continue with the rest of the page after
finishing with your tag, so the 
doEndTag
 method should return 
EVAL_PAGE
. If
you want to abort the processing of the rest of the page, you can return
SKIP_PAGE
 instead.
Listing 14.10 defines a tag for a heading element that is more flexible than
the standard HTML 
H1
 through 
H6
 elements. This new element allows a pre 
cise font size, a list of preferred font names (the first entry that is available on
the client system will be used), a foreground color, a background color, a bor 
der, and an alignment (
LEFT
, 
CENTER
, 
RIGHT
). Only the alignment capability
is available with the 
H1
 through 
H6
 elements. The heading is implemented
through use of a one cell table enclosing a 
SPAN
 element that has embedded
style sheet attributes. The 
doStartTag
 method generates the 
TABLE
 and
SPAN
 start tags, then returns 
EVAL_BODY_INCLUDE
 to instruct the system to
include the tag body. The 
doEndTag
 method generates the
 
 and
 tags, then returns 
EVAL_PAGE
 to continue with normal page pro 
cessing. Various 
setAttributeName
 methods are used to handle the
attributes like 
bgColor
 and 
fontSize
. 
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

jsp web hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Jsp Web Hosting Cheapest Web Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved