DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=16830>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=16830

Jasper do not reset BodyContent for tags with BodySupport and empty content





------- Additional Comments From [EMAIL PROTECTED]  2004-03-29 21:32 -------
A mail from Mark Roth is included here for documentation.

--------------
Hi Issa,

Thanks for your follow-up question.

I'd like to take a moment to acknowledge and say that it's unfortunate 
we ever had the reuse protocol to begin with.  It has caused nothing but 
problems and every release of the spec we end up clarifying it one way 
or another.  Containers implement it differently, and it is the primary 
source of incompatibilities between JSP containers.  It's very hard to 
test because it's so complex.  In addition, we did some rough 
performance guages and it does not seem to improve performance in any 
considerable way, at least with modern VMs.  This is why we went with no 
reuse mechanism for the SimpleTag API in JSP 2.0.

[EMAIL PROTECTED] wrote:
> Indeed, I am in the thread on a Tomcat bug!
> 
> Anyway, you did not fully answer my 1st question. If I can request a 
> little bit more of your time... ;)
> 
> You can find the comment of Kin-Man below. In the example given by him, 
> the 3rd tag invocation will reuse the tag on the 1st invocation. For 
> that 3rd tag, doStartTag will return SKIP_BODY. Thus, in the doEndTag, 
> Kin-Man suggests it is an error to try using the bodycontent. My 
> question is, in this particular case, how can doEndTag know the return 
> value of doStartTag?

Sorry for missing this aspect of your question.  You raise a good point. 
  I read the spec in more detail and found the following relevant sections:

-----
JSP.13.2

The JSP page implementation will create a BodyContent if the 
doStartTag() method returns a EVAL_BODY_BUFFERED. This object will be 
passed to doInitBody(); then the body of the tag will be evaluated, and 
during that evaluation out will be bound to the BodyContent just passed 
to the BodyTag handler. Then doAfterBody() will be evaluated. If that 
method returns SKIP_BODY, no more evaluations of the body will be done; 
if the method returns EVAL_BODY_AGAIN, then the body will be evaluated, 
and doAfterBody() will be invoked again.

The content of a BodyContent instance remains available until after the 
invocation of its associated doEndTag() method.

...

A BodyContent is made available to a BodyTag through a setBodyContent() 
call. The tag handler can use the object until after the call to doEndTag().
-----

The above makes it very clear that after the doEndTag() method is 
called, the tag handler is not to access the BodyContent.  The 
BodyContent is not available again until the next time doStartTag() 
method returns EVAL_BODY_BUFFERED.  A tag that tries to access the 
BodyContent at any other time will get undefined behavior.

We could have required the container to throw an exception if you access 
BodyContent at an unreasonable time, but this would degrade performance.

Note that the third case is different than the second case.  The second 
case required a change to Tomcat because even if the tag returns 
EVAL_BODY_BUFFERED, the rules in the specification specfically state 
that setBodyContent() is not called if the tag has no body.  So to keep 
Tomcat in compliance with the spec, we needed to make sure the tag 
instance was not reused.  This is not necessary in the third case 
because a tag that abides by the rules in the specification will never 
encounter any problems.

> Is it the responsibility of the tag programmer to keep the return value 
> of doStartTag?

It is the responsibility of the tag developer to ensure that BodyContent 
is not accessed when it is not avaialble.  For some tags, you may need 
to keep track of whether you indicated to evaluate the body buffered. 
In this particular tag handler, you could either keep track of the 
return value, or look at the value of the 'content' attribute.

> Should the tag programmer reset the bodycontent himself whenever 
> appropriate?

No.  setBodyContent() is never to be called by tag handlers directly - 
it is a method that the container invokes.

> Is there a document available that *explicitly* explain the INIT 
> protocol and the status of the parameters (including bodycontent) of a 
> tag during its whole life time (with several reuse, several 
> required/non-required parameters)?

There are other rules scattered throughout the spec, but section 
JSP.13.2 and JSP.13.2.2, page 2-70 outline the protocol in detail, with 
diagrams.

> Several J2EE 1.3 certified JSP containers do handle custom tags 
> differently, how come they have been certified? For instance, WebLogic 
> does handle this kind of tags differently than Tomcat.

It's quite easy to write a tag that relies on behavior that is undefined 
in the spec, so even if all containers were spec compliant, there may 
still be differences in behavior in the areas not defined by the spec.

The TCK is developed by identifying the many hundreds of assertions in 
the specification and API javadocs.  Based on these assertions, the test 
writers prioritize and write as many tests as they can.  We do not have 
100% coverage of all assertions due to resource constraints.  I believe 
we have a fairly high coverage rate in this area because it's such a 
potential point of incompatibility.

The source of incompatibility in this area is not due to the lack of 
tests in the TCK but rather the unfortunate inherent complexity of the 
tag reuse protocol.  Most tag library developers (even experienced ones) 
do not fully understand the tag reuse protocol and it's easy to make a 
naive mistake.  In fact, I assure you even I've fallen victim to this in 
tag handlers I've written.

We used this as a justification to create a new tag handler protocol in 
JSP 2.0 called SimpleTag.  SimpleTag tag handlers are never reused by 
the container and have a simple method doTag() instead of the complex 
doStartTag(), doAfterBody(), doEndTag(), etc. lifecycle.

I hope this helps!

---
Mark Roth, Java Software
JSP 2.0 Specification Lead
Sun Microsystems, Inc.

Hi Issa,

Thanks for your follow-up question.

I'd like to take a moment to acknowledge and say that it's unfortunate 
we ever had the reuse protocol to begin with.  It has caused nothing but 
problems and every release of the spec we end up clarifying it one way 
or another.  Containers implement it differently, and it is the primary 
source of incompatibilities between JSP containers.  It's very hard to 
test because it's so complex.  In addition, we did some rough 
performance guages and it does not seem to improve performance in any 
considerable way, at least with modern VMs.  This is why we went with no 
reuse mechanism for the SimpleTag API in JSP 2.0.

[EMAIL PROTECTED] wrote:
> Indeed, I am in the thread on a Tomcat bug!
> 
> Anyway, you did not fully answer my 1st question. If I can request a 
> little bit more of your time... ;)
> 
> You can find the comment of Kin-Man below. In the example given by him, 
> the 3rd tag invocation will reuse the tag on the 1st invocation. For 
> that 3rd tag, doStartTag will return SKIP_BODY. Thus, in the doEndTag, 
> Kin-Man suggests it is an error to try using the bodycontent. My 
> question is, in this particular case, how can doEndTag know the return 
> value of doStartTag?

Sorry for missing this aspect of your question.  You raise a good point. 
  I read the spec in more detail and found the following relevant sections:

-----
JSP.13.2

The JSP page implementation will create a BodyContent if the 
doStartTag() method returns a EVAL_BODY_BUFFERED. This object will be 
passed to doInitBody(); then the body of the tag will be evaluated, and 
during that evaluation out will be bound to the BodyContent just passed 
to the BodyTag handler. Then doAfterBody() will be evaluated. If that 
method returns SKIP_BODY, no more evaluations of the body will be done; 
if the method returns EVAL_BODY_AGAIN, then the body will be evaluated, 
and doAfterBody() will be invoked again.

The content of a BodyContent instance remains available until after the 
invocation of its associated doEndTag() method.

...

A BodyContent is made available to a BodyTag through a setBodyContent() 
call. The tag handler can use the object until after the call to doEndTag().
-----

The above makes it very clear that after the doEndTag() method is 
called, the tag handler is not to access the BodyContent.  The 
BodyContent is not available again until the next time doStartTag() 
method returns EVAL_BODY_BUFFERED.  A tag that tries to access the 
BodyContent at any other time will get undefined behavior.

We could have required the container to throw an exception if you access 
BodyContent at an unreasonable time, but this would degrade performance.

Note that the third case is different than the second case.  The second 
case required a change to Tomcat because even if the tag returns 
EVAL_BODY_BUFFERED, the rules in the specification specfically state 
that setBodyContent() is not called if the tag has no body.  So to keep 
Tomcat in compliance with the spec, we needed to make sure the tag 
instance was not reused.  This is not necessary in the third case 
because a tag that abides by the rules in the specification will never 
encounter any problems.

> Is it the responsibility of the tag programmer to keep the return value 
> of doStartTag?

It is the responsibility of the tag developer to ensure that BodyContent 
is not accessed when it is not avaialble.  For some tags, you may need 
to keep track of whether you indicated to evaluate the body buffered. 
In this particular tag handler, you could either keep track of the 
return value, or look at the value of the 'content' attribute.

> Should the tag programmer reset the bodycontent himself whenever 
> appropriate?

No.  setBodyContent() is never to be called by tag handlers directly - 
it is a method that the container invokes.

> Is there a document available that *explicitly* explain the INIT 
> protocol and the status of the parameters (including bodycontent) of a 
> tag during its whole life time (with several reuse, several 
> required/non-required parameters)?

There are other rules scattered throughout the spec, but section 
JSP.13.2 and JSP.13.2.2, page 2-70 outline the protocol in detail, with 
diagrams.

> Several J2EE 1.3 certified JSP containers do handle custom tags 
> differently, how come they have been certified? For instance, WebLogic 
> does handle this kind of tags differently than Tomcat.

It's quite easy to write a tag that relies on behavior that is undefined 
in the spec, so even if all containers were spec compliant, there may 
still be differences in behavior in the areas not defined by the spec.

The TCK is developed by identifying the many hundreds of assertions in 
the specification and API javadocs.  Based on these assertions, the test 
writers prioritize and write as many tests as they can.  We do not have 
100% coverage of all assertions due to resource constraints.  I believe 
we have a fairly high coverage rate in this area because it's such a 
potential point of incompatibility.

The source of incompatibility in this area is not due to the lack of 
tests in the TCK but rather the unfortunate inherent complexity of the 
tag reuse protocol.  Most tag library developers (even experienced ones) 
do not fully understand the tag reuse protocol and it's easy to make a 
naive mistake.  In fact, I assure you even I've fallen victim to this in 
tag handlers I've written.

We used this as a justification to create a new tag handler protocol in 
JSP 2.0 called SimpleTag.  SimpleTag tag handlers are never reused by 
the container and have a simple method doTag() instead of the complex 
doStartTag(), doAfterBody(), doEndTag(), etc. lifecycle.

I hope this helps!

---
Mark Roth, Java Software
JSP 2.0 Specification Lead
Sun Microsystems, Inc.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to