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

Discussion in 'Java' started by shruds, Jan 25, 2006.

  1. shruds

    shruds Guest

    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.
    shruds, Jan 25, 2006
    #1
    1. Advertising

  2. shruds wrote:
    > 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.

    --
    John Bollinger
    John C. Bollinger, Jan 27, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mg
    Replies:
    2
    Views:
    3,101
    Robsta
    Jan 7, 2009
  2. Olav Tollefsen

    Enter key to invoke button event handler?

    Olav Tollefsen, Jan 18, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    622
    Alvin Bruney
    Jan 24, 2004
  3. Replies:
    6
    Views:
    543
  4. Frederick Gotham

    Invoke New Handler

    Frederick Gotham, Nov 6, 2006, in forum: C++
    Replies:
    0
    Views:
    306
    Frederick Gotham
    Nov 6, 2006
  5. mg

    Invoke event handler programatically

    mg, Jul 15, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    132
Loading...

Share This Page