tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary McGath <gmcg...@panix.com>
Subject Custom tag life cycle
Date Mon, 03 Feb 2003 14:13:47 GMT
The webapp which I am developing (see http://www.timeczar.com for
details) uses a moderately complex custom tag library, and I've found
the lifecycle of a TagSupport object to be very confusing.

As I understand it, a TagSupport object may (but is not guaranteed to)
be reused for subsequent occurrences of the same tag in a JSP.  This
means that attribute variables can't safely be initialized in the
constructor, because they may not get reinitialized for subsequent
occurrences of the tag.  (Here I'm assuming that setter functions for
attributes simply set an instance variable.) 

After some digging, I found that the recommended way to reset attribute
instance varaibles is to use the doEndTag method.  This probably doesn't
work if a tag is nested within a tag of the same name, but I can live
with that.

Doing this works fine in Tomcat.  However, I recently ported my webapp
to Resin and found that it doesn't work there.  Here's a cut-back
excerpt from my JSP:

<caltags:eventset>
    <caltags:evtstartdate mode="date" length="m"/> -
    <caltags:evtenddate mode="date" length="m"/>
</caltags:eventset>

The class which implements eventset includes the tag body once for each
event in the set.  The evtstartdate and evtenddate tags are implemented
by a class called DateTag, which extends TagSupport. Under Tomcat,
DateTag.setMode and DateTag.SetLength get called once for each tag in
each inclusion of the tag body.  Under Resin, only two calls (one for
each of the date tags) are made to each of setMode and setLength.  If I
clear the mode and length fields when I call doEndTag, then all
occurrences of the date tags except the first take on their default
attributes, which is not the behavior I want.

Are both Tomcat and Resin within spec in implementing different
behaviors here?  If so, what is the correct point in the lifecycle to
reset attribute values in a TagSupport object?

Gary McGath       http://www.mcgath.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message