Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Return SKIP_PAGE from doStartTag()

 
Piotr Nowicki
Ranch Hand
Posts: 611
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!
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2445
96
Android Chrome Eclipse IDE
  • 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: 611
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic