Class 2 |
Intermediate Java 30-IT-397 |
|
Repeating a Tag Multiple Times
-
By using the return type of the doAfterBody method in the tag handler,
you can repeat a body multiple times.
-
return(SKIP_BODY); will only write it once.
-
return(EVAL_BODY_TAG); will write it again. You can do this recursively.
-
Let's make an application to register for health insurance. The user
will first enter the number of dependents. Then, a new page will
generate with a form, with one row of entry fields per dependent.
-
The files:
-
Registration.html The first form
the user sees, where he enters the number of dependents.
-
Register.jsp The jsp that generates the
form for entry of dependent info.
-
Repeat.java The tag handler class, takes
the number of repetitions as input and generates the body of Register.jsp.
-
utils.tld The tag library defintion file.
-
And, of course, this entry into web.xml:
<taglib>
<taglib-uri>/utils</taglib-uri>
<taglib-location>utils.tld</taglib-location>
</taglib>
The Result

Created by: Brandan Jones
December 17, 2001