tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Moore" <tmo...@blackboard.com>
Subject RE: Custom tag life cycle
Date Mon, 03 Feb 2003 19:34:22 GMT
> -----Original Message-----
> From: Will Hartung [mailto:willh@msoft.com] 
> Sent: Monday, February 03, 2003 1:38 PM
> To: Tomcat Users List
> Subject: Re: Custom tag life cycle
> 
> 
> > From: "Tim Moore" <tmoore@blackboard.com>
> > Sent: Monday, February 03, 2003 9:30 AM
> > Subject: RE: Custom tag life cycle
> 
> 
> > But I would do the initialization in doStartTag rather than 
> doEndTag. 
> > The latter may not be called if an exception is thrown from 
> within the 
> > tag body.
> 
> The problem here is that the doStartTag is done after all of 
> the properties are set.
> 
> So, you don't know if a property value has been set from the 
> current tag invocation or an earlier tag invocation.
> 
> I think Felipes idea of using the doFinally as a "reset to 
> default contructed state" is the smartest thing. I'd like to 
> hope that the new JSP spec clarifies the lifecycle a bit 
> better, taking in to account the aggressive caching that the 
> containers are doing now.


But did you see the rest of my message?  It's important to not actually
reset the instance variables between invocations.  So really, you don't
want to intialize those at all, but invocation-specific local variables.

More from the JSP 1.2 spec:

s.10.1:
"It is the
responsability of user code, be it scriptlets, JavaBeans code, or code
inside custom
tags, to not invoke these setter methods, as doing otherwise would
interfere with
the container knowledge."

"Once properly set, all properties are expected to be persistent, so
that if the
JSP container ascertains that a property has already been set on a given
tag
handler instance, it needs not set it again."

s.10.1.1 :
"After the doEndTag invocation, the tag
handler is available for further invocations (and it is expected to have
retained its
properties)."

So I misstated; you don't want to initialize properties themselves in
doStartTag, you want to do something like this:

String attr1 = this.attr1;
if (attr1 == null) {
  attr1 = DEFAULT_ATTR1;
}

etc.

-- 
Tim Moore / Blackboard Inc. / Software Engineer
1899 L Street, NW / 5th Floor / Washington, DC 20036
Phone 202-463-4860 ext. 258 / Fax 202-463-4863

---------------------------------------------------------------------
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