File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Parent and Child Tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Parent and Child Tags" Watch "Parent and Child Tags" New topic

Parent and Child Tags

Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
I cannot figure out how the Parent to Child and Child to Parent Tags are working .
There is some code in HFJS pg 573.

Can some one tell me the sequence of how the code is running .
When the setItemValue() and addMenuITem() are running.
Also the sequence of the respective doStartTag() and doEndTAg() runs.

Can't make any sense out of it.!

The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Nabila. If jsp page invokes,
first container finds appropriate tld file. After that, Menu tag handler will be invoked and the life cycle of Menu tag handler starts. Loads, setting PageContext object, setting parent (here there is no parent so 'null' will passed), setting attributes(here there are no attributes), and calls the doStartTag(). Here in doStartTag() ArrayList object is created, and return's EVAL_BODY_INCLUDE. Now the container process the body.
Here body of Menu tag includes . First MenuItem tag handler will be invoked and its life cycle starts. Loads first MenuItem class class, instantiate, sets the parent(here parent is Menu tag handler object), sets the attributes(here sets the attribute name "Dogs" by using setItemValue(String name) method of it ), and calls the doStartTag(). Here doStartTag() return's EVAL_BODY_INCLUDE. The body of the MenuItem will be processed(here there is no body). After that it calls the doEndTag() of it. In doEndTag(), gets it's parent tag(Menu tag handler object) and calls the addMenuItem(itemValue) of it by passing the itemValue "Dogs" to it.The addMenuItem(String item) of Menu tag hander adds attribute value "Dogs" to the ArrayList object. Finally it returns EVAL_PAGE, means the rest of page will be evaluated.

Similarly it calls second, third and adds "Cats", "Horses" to ArrayList object.

All this is happened while container processing the body of Menu tag handler. After processing the body, finally container calls the doEndTag() of Menu tag handler class. Here it process
Finally the method returns EVAL_PAGE, and the rest of the page will be evaluated and the response will be sent to the client.
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
Thanks alot Chinmaya , that was a nice and detailed explanation.

Still trying to get a hang out it. Keep forgetting the previous stuff I learned.

Was wondering..How do you write a TLD for nested tags?
I agree. Here's the link:
subject: Parent and Child Tags
It's not a secret anymore!