You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by Henri Yandell <ba...@generationjava.com> on 2002/10/14 02:31:39 UTC

Creating a fake Taglib lifecycle

[This is driven by a bug in the String taglib].

In the String taglib code I attempted to write a StringTagSupport class
which gave me a more defined taglib lifecycle. It hit a bug in that when a
container is looping around a tag, it doesn't have to set the Tag object
up each time.

The problem being that I re-init tags at the end of invocation, and the
container never resets the attributes before calling again.

Example:

 <loop>
     <str:qqq name="boo">Blah</str:qqq>
 </loop>

So the first time the container sets it up, calls setName("boo") and
invokes correctly. After the String stuff is done, I set the name back to
its default [which is null because name is required].
The second time the container skips the invocation. I have a null.
NPE-alarms go off.

So the immediate solution is to stop re-initialising the attributes.

However, that will [I believe??] give me the following bug:

// <str:fff age="42">Bink</str:fff>
// <str:fff>Bink</str:fff>

The second tag will not have the age reset to 21 [the default age] but
will instead still be 42 on occasions when the container reuses the same
object [???]. So I have to re-init it this time.

However, it's very hard to be able to choose which.

I suspect I'm either missing something, or am basing my thoughts on a
mistaken assumption.

Any ideas?

Hen


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Creating a fake Taglib lifecycle

Posted by Shawn Bayern <ba...@essentially.net>.
On Sun, 13 Oct 2002, Hans Bergsten wrote:

> Shawn's answer is right on, but if your interested, I cover a few
> additional important JSP 1.2 lifecycle issues in an article on
> ONJava.com:
> 
>    <http://www.onjava.com/pub/a/onjava/2001/11/07/jsp12.html>

Also, there's a (somewhat dry but thorough) treatment at

  http://jakarta.apache.org/taglibs/guidelines

Shawn


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Creating a fake Taglib lifecycle

Posted by Hans Bergsten <ha...@gefionsoftware.com>.
Henri Yandell wrote:
> [This is driven by a bug in the String taglib].
> 
> In the String taglib code I attempted to write a StringTagSupport class
> which gave me a more defined taglib lifecycle. It hit a bug in that when a
> container is looping around a tag, it doesn't have to set the Tag object
> up each time.
> 
> The problem being that I re-init tags at the end of invocation, and the
> container never resets the attributes before calling again.
> 
> Example:
> 
>  <loop>
>      <str:qqq name="boo">Blah</str:qqq>
>  </loop>
> 
> So the first time the container sets it up, calls setName("boo") and
> invokes correctly. After the String stuff is done, I set the name back to
> its default [which is null because name is required].
> The second time the container skips the invocation. I have a null.
> NPE-alarms go off.
> 
> So the immediate solution is to stop re-initialising the attributes.
> 
> However, that will [I believe??] give me the following bug:
> 
> // <str:fff age="42">Bink</str:fff>
> // <str:fff>Bink</str:fff>
> 
> The second tag will not have the age reset to 21 [the default age] but
> will instead still be 42 on occasions when the container reuses the same
> object [???]. So I have to re-init it this time.
> 
> However, it's very hard to be able to choose which.
> 
> I suspect I'm either missing something, or am basing my thoughts on a
> mistaken assumption.
> 
> Any ideas?

Shawn's answer is right on, but if your interested, I cover a few
additional important JSP 1.2 lifecycle issues in an article on
ONJava.com:

   <http://www.onjava.com/pub/a/onjava/2001/11/07/jsp12.html>

Hans
-- 
Hans Bergsten		hans@gefionsoftware.com
Gefion Software		http://www.gefionsoftware.com
JavaServer Pages	http://TheJSPBook.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Creating a fake Taglib lifecycle

Posted by Shawn Bayern <ba...@essentially.net>.
On Sun, 13 Oct 2002, Henri Yandell wrote:

> So the first time the container sets it up, calls setName("boo") and
> invokes correctly. After the String stuff is done, I set the name back to
> its default [which is null because name is required].

This is the bug right here; this runs against the mandates of the
tag-handler lifecycle protocol as defined in the JSP 1.2 specification.

> However, that will [I believe??] give me the following bug:
> 
> // <str:fff age="42">Bink</str:fff>
> // <str:fff>Bink</str:fff>
> 
> The second tag will not have the age reset to 21 [the default age] but
> will instead still be 42 on occasions when the container reuses the
> same object [???]. So I have to re-init it this time.

No you don't:  the JSP 1.2 specification specifically prevents the tag
handler from being reused in this latter case, as the two tags have
different "attribute sets."  (This concept of attribute set is designed
precisely to address the ambiguity you raise.)

The proper behavior is *not* to reinitialize the values in doEndTag() and
to allow your properties to change only through their correspondent
accessors.

Hopefully, nobody will ever need to learn any of this stuff after JSP 2.0.  
:-)

-- 
Shawn Bayern
"JSTL in Action"   http://www.jstlbook.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>