Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Return SKIP_PAGE from doStartTag()

 
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Ranchers!

While solving Niko's tests about Custom Tags I've bumped into quite interesting question which asks what will happen if doStartTag() will return SKIP_PAGE.

Here is an exemplary code:

com.example.MyTag2.java


test.jsp



This code returns Howdy! test! so it's fine. The following are the results summary:

1. doStartTag returns EVAL_BODY_INCLUDE and doEndTag returns SKIP_PAGE instead of EVAL_PAGE
Result: Howdy! (which is OK - the tag gets evaluated but the rest of the page is not processed)

2. doStartTag returns SKIP_PAGE and doEndTag returns EVAL_PAGE
Result: test! (which is quite unusual for me... the SKIP_PAGE in doStartTag makes the tag not to evaluate it's body and... that's it? No more meaning of SKIP_PAGE?)

I've ran some tests and firstly I thought it's because the SKIP_PAGE might return the same integer value as SKIP_BODY which might explain the behavior shown above. It's integers and not enums so such kind of things might happen.

But then again I've tested that if I return a random integer from the doStartTag() method like:

the body of the tag doesn't get evaluated as well!

My suspects are that the body gets evaluated only if the doStartTag() returns EVAL_BODY_INCLUDE or EVAL_BODY_BUFFERED and in other cases it just treats it like SKIP_BODY.
Can anybody confirm this version?

Thanks in advance!

Cheers!
 
Creator of Enthuware JWS+ V6
Posts: 3348
303
Android Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pedro!

My suspects are that the body gets evaluated only if the doStartTag() returns EVAL_BODY_INCLUDE or EVAL_BODY_BUFFERED and in other cases it just treats it like SKIP_BODY.
Can anybody confirm this version?


Yes, that is correct.

Just have a look at the implementation of the tag (in the tomcat servlet container): there is an explicit check on either EVAL_BODY_INCLUDE or EVAL_BODY_BUFFERED.

In the JSP2.0 specs there is nothing about what the tag handler should do if there is another integer value returned from the methods

Regards,
Frits
 
Piotr Nowicki
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frits!

I've tried to read the default behaviour basing on Javadocs and specs, but as you already mentioned - I couldn't find any answer.
I'll check the Tomcat source code :-)

Cheers!
 
Create symphonies in seed and soil. For this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic