Chapter 21. Advanced Custom Tag Library Features

In the previous chapter, you learned how to develop basic tag handlers, such as conditional and iteration actions, with and without access to the element body. But there’s a lot more that you can do. In this chapter we look at some more advanced features: how actions can cooperate, how to verify that actions are used correctly, how to bundle listener classes with a tag library, and how to convert text attribute values into types more appropriate for the tag handler.

Developing Cooperating Actions

It’s often necessary to develop custom actions so that they can be combined with other actions, letting them cooperate in some fashion. You have seen examples of this throughout this book. For instance, in Chapter 11, <sql:param> action elements are nested within the body of a <sql:query> action to set the values of placeholders in the SQL statement. Another example of cooperation is how the <c:forEach> action can use the query result produced by the <sql:query> action. In this section, we take a look at the cooperation techniques demonstrated by these two examples: explicit cooperation between a parent element and elements nested in its body and implicit cooperation through objects exposed as scoped variables.

Using Explicit Parent-Child Cooperation

One example of explicit parent-child cooperation is the <ora:forward> action with nested <ora:param> actions used in Chapter 10:

<ora:forward page="product1.jsp"> <ora:param name="id" value="${}" ...

Get JavaServer Pages, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.