views:

184

answers:

1

I have written a JSP custom tag, implemented in a class that extends TagSupport, and I'd like to invoke another custom tag that was written as a *.tag file. Is this possible? If so, how can it be done?

A: 

You can't, tag files can only be executed from a JSP.

Even executing one tag class from another is questionable, you're not supposed to do that either (although it would probably work).

If you need reusable logic that gets invoked from your tag class, then you either need to extract it out into a common class, or else you need to make your custom tag into a BodyTag, and put the .tag file in as nested content withoin it, e.g. if tagX is a taglib, and tagY is a tag file, then:

<mylib:tagX>
   <mytags:tagY/>
</mylib:tagX>

The output content of <mytags:tagY/> would then be exposed to the tagX code via the BodyTag interface.

skaffman
Hey, you accepted the answer before I had a chance to flesh it out :)
skaffman
Bummer, that's what I was afraid of. My goal was to have several tag files as little editing widgets (e.g. one for String editing, one for Date editing), in order to format a wide variety of data types. The JSP custom tag would invoke the correct tag file based on the desired data type. I guess I'm going to fall back to using a monstrous <c:choose> block, since that's all I can think of.
Will