The Java EE 5 Tutorial

Communication between Tags

Custom tags communicate with each other through shared objects. There are two types of shared objects: public and private.

In the following example, the c:set tag creates a public EL variable called aVariable, which is then reused by anotherTag.

<c:set var="aVariable" value="aValue" />
<tt:anotherTag attr1="${aVariable}" />

Nested tags can share private objects. In the next example, an object created by outerTag is available to innerTag. The inner tag retrieves its parent tag and then retrieves an object from the parent. Because the object is not named, the potential for naming conflicts is reduced.

    <tt:innerTag />

The Duke’s Bookstore page tut-install/javaeetutorial5/examples/web/bookstore3/web/template/template.jsp uses a set of cooperating tags that share public and private objects to define the screens of the application. These tags are described in A Template Tag Library.