SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 401 | Next

Larry Brown, Marty Hall, and Yaakov Chaikin

"Core Servlets and JavaServer Pages, Volume 2"


Core Note
When getJspBody().invoke(null) is called, it is the output
resulting from the execution of the tag body??™s JSP content that gets
passed to the client, not the JSP code itself.
7.5 Including Tag Body in the Tag Output 363
In practice, you almost always output something before or after outputting the tag
body as follows:
JspWriter out = getJspContext().getOut();
out.print("...");
getJspBody().invoke(null);
out.print("...");
Note that because sending the JSP content of the tag body boils down to a simple
method invocation, it is very easy to create a tag that conditionally sends the JSP content
to the client by surrounding the method call with an if statement. We show an
example of this in Section 7.7 (Example: Debug Tag). It is also trivial to output the
tag body content several times, as the method call can be placed inside a for loop
and invoked many times. We show an example of this in Section 8.4 (Example: Simple
Looping Tag).
Tag Bodies: Tag Library Descriptor
The change to the TLD is trivial. Instead of the value of empty for the required
body-content element, we need to provide the value of scriptless.
Tag Bodies: JSP File
There are no changes to the JSP file. You still need to declare and assign a prefix
to the TLD through the taglib directive. However, now we can use our tags with
nonempty bodies.
Remember, however, that the body-content was declared as scriptless,
and that scriptless means we are allowed to place JSP content into the body of
the tag, but are not allowed to place JSP scriptlets there.


Pages:
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413