Custom tags - When does a parent tag know about its child tags?

J

johkar

Bear with me because I am new at this. Is there a way for the
beginning <layout:apppage> tag to know what all of its child tags are
before the child tags are invoked? The leftnav and rightnav tags are
optional and I need to output HTML differently in the beginning
apppage tag based on what is present.

<layout:apppage>
<layout:leftnav> <!-- code here --> </layout:leftnav>
<layout:rightnav> <!-- code here --> </layout:rightnav>

<!-- my app code -->

</layout:apppage>

Also, both leftnav and rightnav have child tags of their own, I am
having trouble figuring out how to save all the HTML they generate and
output it with the ending apppage tag.

Thanks
 
D

Dan Andrews

Bear with me because I am new at this. Is there a way for the
beginning <layout:apppage> tag to know what all of its child tags are
before the child tags are invoked? The leftnav and rightnav tags are
optional and I need to output HTML differently in the beginning
apppage tag based on what is present.

<layout:apppage>
<layout:leftnav> <!-- code here --> </layout:leftnav>
<layout:rightnav> <!-- code here --> </layout:rightnav>

<!-- my app code -->

</layout:apppage>

Also, both leftnav and rightnav have child tags of their own, I am
having trouble figuring out how to save all the HTML they generate and
output it with the ending apppage tag.

Thanks


Have a look at the article that Jeff Wilson wrote titled "Take control
of your JSP pages with custom tags." There is also a good code sample
there that you can download. Here is the link:
http://www-128.ibm.com/developerworks/java/library/j-taglib/

Cheers,

Dan Andrews
 
T

Tom Hawtin

johkar said:
Bear with me because I am new at this. Is there a way for the
beginning <layout:apppage> tag to know what all of its child tags are
before the child tags are invoked? The leftnav and rightnav tags are
optional and I need to output HTML differently in the beginning
apppage tag based on what is present.

The simple answer is no.

The possibly more useful answer is that you can evaluate the body, but
defer from passing on the output. If you buffer the output. then you can
change the header depending upon how the execution went within the body.

I've not done this sort of thing for five or six years, so can't
remember the details of the APIs. Example code is left as an exercise
for the reader.

Tom Hawtin
 
J

johkar

johkarwrote:

The simple answer is no.

The possibly more useful answer is that you can evaluate the body, but
defer from passing on the output. If you buffer the output. then you can
change the header depending upon how the execution went within the body.

I've not done this sort of thing for five or six years, so can't
remember the details of the APIs. Example code is left as an exercise
for the reader.

Tom Hawtin

Thank you.
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top