aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Return SKIP_PAGE from doStartTag() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Return SKIP_PAGE from doStartTag()" Watch "Return SKIP_PAGE from doStartTag()" New topic
Author

Return SKIP_PAGE from doStartTag()

Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

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!


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1731
    
  25

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

Joined: Jul 13, 2010
Posts: 610

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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Return SKIP_PAGE from doStartTag()