Nested Tags

The Struts custom tag libraries provide a great deal of power and flexibility to the developer. The freedom to access properties of a bean at any level using nested properties is very powerful.

There are some restrictions in how this technique can be deployed, however. When attempting to nest one tag inside another, the inside tag has certain dependencies on the outside tag that may make it cumbersome or impossible to cleanly render the dynamic data. There are workarounds, but these usually involve using scriptlets with Java within the JSP page. “Nested” tags were created to solve this problem and to enrich the Struts tag libraries.

The Nested tag library was created by Arron Bates to make it easier to nest Struts tags inside one another and to match the ability of the model layer to nest beans inside one another. The nested tags have become so popular that they have been added to the core libraries.

Nested tags parallel the current tags supported by the Struts framework. For example, there are HTML nested tags, Logic nested tags, and Bean nested tags. There is no need for nested Template tags, so those don’t exist. The major difference is that nesting is better supported in the nested versions.

The tags within the Nested tag library are used in the same way that the non-nested versions are. Minor differences exist to allow for tags to know when they are nested within one another and therefore can access properties of the parent tag. Other than these small differences, ...

Get Programming Jakarta Struts, Second Edition 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.