Processing the Action Body
As you can see, it’s easy to develop a
tag handler that doesn’t need
to do anything with the action element’s body. For a tag
handler that does need to process the body, however, just a few more
methods are needed. They are defined by the
BodyTag
interface, which extends the
Tag
interface.
The action element’s body has many possible uses. It can be
used for input values spanning multiple lines; the
SQL custom actions introduced in Chapter 9, use
the body this way. The SQL statement is often
large, so it’s better to let the page author write it in the
action body instead of forcing it to fit on one line, which is a
requirement for an attribute value. The body can also contain nested
actions that rely on the enclosing action in some way. The
<ora:sqlTransaction>
action, also from
Chapter 9, provides the nested SQL actions with
the DataSource
object they use to communicate with
the database, and ensures that the SQL statements in all actions are
treated as one transaction that either fails or succeeds.
A third example is an action that processes the body content in one way or another before it’s added to the response. Chapter 12, contains an example of an action that processes its XML body using the XSL stylesheet specified as an attribute. Later in this section we look at an action that replaces characters that have special meanings in HTML with the corresponding HTML character entities.
As with the Tag
interface, there’s a
BodyTagSupport
class that ...
Get Java Server Pages now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.