Re: JSP tags and tag recycling
From: John C. Bollinger (jobollin_at_indiana.edu)
Date: 03/14/05
- Next message: Malte: "Re: Java tools"
- Previous message: Andrea Desole: "Re: JSP - saving textfield values before loading 'intermediate' page"
- In reply to: plm: "JSP tags and tag recycling"
- Next in thread: plm: "Re: JSP tags and tag recycling"
- Reply: plm: "Re: JSP tags and tag recycling"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 14 Mar 2005 11:47:03 -0500
plm wrote:
> Hello,
>
> I have always believed that due to the possibility of tag recycling,
> that is the JSP engine may reuse tag instances (the only guarantee you
> have is that no multiple threads are inside a tag instance at the same
> time), one has to reset all non-mandatory attributes to their default
> values in doEndTag(), that is before the tag may be used again.
>
> I have seen various recommendations to do this.
It depends on the details, but such recommendations are typically flat
wrong. In part _because_ of tag reuse, it is *forbidden* by JSP for any
tag handler state exposed as an attribute, whether optional or required,
to be modified by any means other than that attribute, as provided by a
page implementation using the handler. Furthermore, it is (or should
be) unnecessary to reset tag parameters that have not been changed from
their default values. That means that you shouldn't ever touch tag
parameters programmatically, except at instantiation and release.
> However, all Struts tags do something else, something strange: they
> reset the tag attributes to their default values in the release()
> method, which is meant to release any resources (such as JDBC
> connections etc) a tag instance might have. AFAIK an attribute value is
> not a resource :).
What if the value is a JDBC Connection? Or a large Collection?
> If I'm not wrong, release() is only called when the tag instance is
> destroyed, not between reuses of the current tag instance. So the
> struts way of doing things might lead to unexpected results, where tags
> attributes of reused tags do not have their documented default values.
The release() method is guaranteed to be invoked when the JSP container
is done with a tag handler instance, before that instance becomes
eligible for GC. If Struts provides some kind of level 2 caching for
tag handler instances, or otherwise has to worry about instances hanging
around past their usefulness, then it makes sense to reset attributes in
release(). Otherwise it is pointless (but not wrong).
As for tag handlers and attribute values, it is precisely when programs
violate JSP's restrictions about mucking with tag handlers' attributes
that problems may arise. In code written as you seem to prefer, the
problems would tend to take the form of a tag attribute having its
default value when it was supposed to have a customized one.
> The question is, is my understanding of the JSP spec w.r.t. tag
> recycling wrong, or is struts wrong?
Your understanding is wrong. Struts might be doing unnecessary work,
but you are proposing non-compliant code.
-- John Bollinger jobollin@indiana.edu
- Next message: Malte: "Re: Java tools"
- Previous message: Andrea Desole: "Re: JSP - saving textfield values before loading 'intermediate' page"
- In reply to: plm: "JSP tags and tag recycling"
- Next in thread: plm: "Re: JSP tags and tag recycling"
- Reply: plm: "Re: JSP tags and tag recycling"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|