aspose file tools*
The moose likes JSP and the fly likes Tag Handler's Lifecycle - Nested Tags of the same class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Tag Handler Watch "Tag Handler New topic
Author

Tag Handler's Lifecycle - Nested Tags of the same class

Ross Sargant
Greenhorn

Joined: Oct 28, 2002
Posts: 4
Hi,
There is something I just can't seem to understand regarding a tag handlers lifecyle.
If you have a situation where you have
a nested tag of the same type (ie: same tag handler class) how many instances of that class are in existence, and is there even some kind of guarentee?
Lets say you are doing nested iteration, so you have two nested iteration tags. Furthermore, lets say that for some reason, your iteration tag needs to refer to its enclosing tag.
Is it ever the case that findAncestorWithClass(..)
will return *this*? Is there always two instances of tag handler around in this nested situation or might there only be one?
I just can't seem get a solid understanding of whats going on there. I understand in general, that a tag handler can be reused but will it ever be reused to handle the nesting of itself?
Maybe there is some obvious reason why this isn't possible.. any clarification of what goes on here would be appreciated!
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
In this situation, there must be two tag handler instances. Since the getParent() method returns the closest enclosing parent, having the same return value for both tags wouldn't make sense. Also, setting values for the tag attributes would overwrite those of the enclosing (parent) tag if the same instance was (re)used.
Hope that helps...
Simon
p.s. I dedicated a section to this in chapter 9 of my book if you have access to a copy
[ October 28, 2002: Message edited by: Simon Brown ]
Ross Sargant
Greenhorn

Joined: Oct 28, 2002
Posts: 4
Thank you!
I have been looking for a good answer to this everywhere but nobody ever seemed to understand what I was asking.
Perhaps I will need to get a copy of your book.
So, the bottom line is that for nested tags of the same tag handler class, there will always be as many instances as the depth of the nesting tree, and each has its own state and getParent.. findAcestor never return "this".
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
Yes (well, atleast I hope so!).
Simon
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tag Handler's Lifecycle - Nested Tags of the same class