how do u invoke Tag b's Tag Handler from within Tag a's tag Handler?

S

shruds

i want to have a custom tag to render tabs onto the screen. this tag
will have custom tags nested inside it which are the tabs that have to
be rendered and the tab content for each tab.
like:

<myTab:Tabs>
<myTab: Tab title="Tab1">
<jsp:include "Tab1_Content.jsp/>
</myTab: Tab>

<myTab: Tab title="Tab2">
<jsp:include "Tab2_Content.jsp/>
</myTab: Tab>

<myTab: Tab title="Tab3">
<jsp:include "Tab3_Content.jsp/>
</myTab: Tab>
</myTab: Tabs>


how can a tag Handler invoke the Tag handler of another tag?
Thanks in advance.
 
J

John C. Bollinger

shruds said:
i want to have a custom tag to render tabs onto the screen. this tag
will have custom tags nested inside it which are the tabs that have to
be rendered and the tab content for each tab.
like:

<myTab:Tabs>
<myTab: Tab title="Tab1">
<jsp:include "Tab1_Content.jsp/>
</myTab: Tab>

<myTab: Tab title="Tab2">
<jsp:include "Tab2_Content.jsp/>
</myTab: Tab>

<myTab: Tab title="Tab3">
<jsp:include "Tab3_Content.jsp/>
</myTab: Tab>
</myTab: Tabs>


how can a tag Handler invoke the Tag handler of another tag?
Thanks in advance.

Your question is a bit unclear. Objects cannot be invoked, though their
methods can be.

My best guess at what you mean is that you want one of your tag handlers
to invoke the life cycle methods of other tag handlers. Let me be very
clear: that is absolutely FORBIDDEN. Tag handlers' life cycle methods
are reserved for use by the JSP container. (And it wouldn't do what you
probably want, anyway.) If that was indeed what you were asking then do
not despair; you don't need to do it in the first place. Read on.

A tag handler can easily obtain a reference to any other tag handler
that logically contains it by use of TagSupport.findAncestorWithClass().
Via that reference, it can invoke any of the containing handler's
methods (but see above, and strong prohibitions also apply to attribute
setters).

You should also pay attention to the BodyTag interface. Chances are
good that the tag handlers you are working on will want to buffer their
bodies. I might design the system along these lines:

(1) [Architectural] The handler for myTab:Tabs provides a method
addTab([SomeAppropriateType]) that is intended for other tag handlers to use
(2) [Behavioral] The handler for myTab:Tabs buffers its body and
discards the result
(3) [Behavioral] The handler for myTab:Tab buffers its body, then in
doEndTag() it looks up the containing myTab:Tabs and invokes its
addTab() method to pass in the relevant information (including the
result of the body evaluation)
(4) [Behavioral] In its own doEndTag(), myTab:Tabs writes out
appropriate code based on all the data passed to its addTab() method
since the last doStartTag() invocation.

You really should read up on all of this in the JSP specification (my
choice) or a suitable reference book. Custom tags aren't that hard once
you get the hang of them, but you can really bring trouble on yourself
if you don't follow all the details of the behavioral contracts that
exist between tag handlers and their container.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top