aspose file tools*
The moose likes JSP and the fly likes Taghandler initilization by the jsp container 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 "Taghandler initilization by the jsp container" Watch "Taghandler initilization by the jsp container" New topic
Author

Taghandler initilization by the jsp container

Anoop Krishnan
Ranch Hand

Joined: May 03, 2001
Posts: 163
I have a nested tag implementation as follows

The Colum tag get the reference to Outer tag DataGrid via the following method

and adds the self reference to a Vector in the DataGrid class.
But when I accessed the objects in the vector, I got shocked there was 5 elements in the vector but all of them referring to the same object. That means the ColumTag is instantiated just once and the same reference is used for all other tags.

How can this happen ?. I thought each time a new tag handler reference is created.

Because of the same problem whenever I reload the page the elements in the vector gets multiplied because there is only one reference of the DataGrid tag generated for the entire page.


I just want to know is there any body call my bean's Getter and Setter methods with "Please" in front - My favorite quip from Bugzilla
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

You didn't say, but I'm assuming from your symptoms that you are using classic tag handlers rather tham JSP 2.0 simple tags.

In classic handlers, the tag instances will be re-used on the page. So you shouldn't be trying to store references to the tags in your vector, but rather copy the information out the passed tag and store some sort of "column descriptor" instead.

Alos, I'd recommend the use of a List implementation (like ArrayList) rather than a Vector.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Anoop Krishnan
Ranch Hand

Joined: May 03, 2001
Posts: 163
Thank You Very Much.

I have 2 doubts one relates to Classic tags & Other with simple tags.


1) So one instance per page is created for the classic tag handlers .Does it mean that the classic tag handling is not thread safe ?

If the tag has a attribute which is a scriplet this can be overwritten from a different thred while the tag hadler is processing the handler routine in its life cycle methods.


2)I am new to JSP 2.0 SimpleTags . I tried it but, How can I implement nested tags using SimpleTagHandler.

Because there is only one method which has to be implemented ie doTag

So there is not possibility to find it is the start tag or the end tag.

I want to so something when all the inner tags are initialized and communicated to the outer tag.So in the doEndTag routine of the outer tag I can perform the final tasks.But this is not possible when I only have one life cycle method for one tag.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Originally posted by Anoop Krishnan:

1) So one instance per page is created for the classic tag handlers


No. The container is free to make as many as it wants. You have no control over how many instances there will be. Generally I find that the containers create one instance of a tag for each unique combination of attributes.

Does it mean that the classic tag handling is not thread safe ?


No, they are thread safe. No tag instance will be called simultaneously, but the same tag instance can be re-used for multipe serial tag references.

If the tag has a attribute which is a scriplet this can be overwritten from a different thred


No. Tag instances are not shared across threads.

I am new to JSP 2.0 SimpleTags . I tried it but, How can I implement nested tags using SimpleTagHandler.

Because there is only one method which has to be implemented ie doTag


With simple tags, you control when the body gets evaluated so there is no need for start and end methods. Code that you place before the body evaluation is the equivalent of "start" code, and code you place after body evaluation is the equivalent of "end" code.


I want to so something when all the inner tags are initialized and communicated to the outer tag.So in the doEndTag routine of the outer tag I can perform the final tasks.But this is not possible when I only have one life cycle method for one tag.


Yes, it is. After the body has been evaluated, all the child tags will have done their thing.
[ June 07, 2006: Message edited by: Bear Bibeault ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Taghandler initilization by the jsp container