• Post Reply Bookmark Topic Watch Topic
  • New Topic

Usings custom tags within your tag handler class

 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Is it possible to use a custom tag within another custom tag's handler class. for example my custom's tag doStratTag buffers up an accessibility:label custom tag. When I view source accessibility:label is not translated. Is there a way to get this to work?

Thanks,

AMD

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Think about it for a minute. The tags get turned into code during the translation phase. Then this code runs when the page is executed. The chances for tags to be translated to code is long passed.

More on JSP life cycle in this article.
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andrew Mcmurray:
Is it possible to use a custom tag within another custom tag's handler class.



To the best of my knowledge, the answer is no. The reason is that the container handles all invocations of tags, matching tags up with their handler instances (in the case of classic tags, from its own pool) as required.

One problem you'll quickly find is that the namespace ("accessibility") isn't bound in your class - the container has no idea what a namespace in a class is anyway, but it does know what to do with one in a JSP.

What is required is some way to use container-level services, like the EL evaluator, VariableResolver and a mechanism for invoking tags. But, the implementations are all container-vendor dependent. While you might be able to find a way on one J2EE implementation to do what you require, this wouldn't be globally deployable.

If the other tag is also in your own tag library, you might think about extracting the core functionality into a helper class, deploy that in the library and reference it from both the "label" tag and the one you're designing. If the other tag resides in another library, there's not much you can do.

However, all is not lost. I noticed that most of your example simply wrote out XML syntax (what we might call "template text") to the page. The only programmatic code is the if...else block and the invocation of the "label" tag. This would suggest to me the use of a Tag File (written in JSP syntax) rather than a tag handler class. This would (a) enable you to do away with the horrid append() and write() expressions, (b) invoke the other action in the normal JSP manner. To get the if...else behaviour, consider using the JSTL Core <c:choose>, <c:when> and <ctherwise> actions.

I would have thought that this should do the trick (you'll need to add in directives as appropriate):




Let me know if that helps (or just seems more confusing!)
[ December 23, 2005: Message edited by: Charles Lyons ]
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I should have written:



rather than:

 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Charles and Bear,
Thanks for the replies. Now why couldn't I have my tag just extend the other tag. Shouldn't that work? I won't be able to try till after Mon when I get back to work.

Thanks,

AMD
[ December 24, 2005: Message edited by: Andrew Mcmurray ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!