Developing Custom Actions
A custom action—actually, a tag handler class for a custom action—is basically a bean, with property setter methods corresponding to the custom action element’s attributes. In addition, the tag handler class must implement one of two Java interfaces defined by the JSP specification.
All the interfaces and classes you need to implement a tag handler
are defined in the javax.servlet.jsp.tagext
package. The two primary interfaces are named Tag
and BodyTag
. The Tag
interface
defines the methods you need to implement for any action. The
BodyTag
interface extends the
Tag
interface and adds methods used to access the
body of an action element. To make it easier to develop a tag
handler, two support classes are defined by the API:
TagSupport
and BodyTagSupport
(shown in Figure 1-4). These classes provide
default implementations for the methods in the corresponding
interfaces.
The specification defines interfaces as well as the support classes that implement them to cover all the bases. If you already have a class with functionality that you want to access as a custom action, you can specify that your class implements the appropriate interface and add the few methods defined by that interface. In practice, though, I recommend that you implement your tag handlers as extensions of the support classes. ...
Get JavaServer Pages Pocket Reference 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.