This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes behaviour of doStartTag of TagSupport Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "behaviour of doStartTag of TagSupport" Watch "behaviour of doStartTag of TagSupport" New topic
Author

behaviour of doStartTag of TagSupport

Royston Monteiro
Ranch Hand

Joined: Apr 25, 2008
Posts: 35

Hi,
My CustomTagHandler that extends TagSupport:


The Jsp that calls this:


I am given to understand that by default(when the doStartTag isnt overridden, the behaviour is to skip the Body. Since I am returning neither of teh expected return values, shouldnt the default behaviour kick in? I assume returning an arbitrary return value integer is similar to not overriding the doStart method as far as default behaviou is concerned. On the contrary, I observe the below output:
The output from the Jsp is

which means that the body is evaluated.

Could someone please suggest.


Cheers,
Roy.
Sun Certified Java Programmer 1.5,
Sun Certified Web Component Developer 5.
"No pain. No Gain"
http://cs.nyu.edu/~rpm319
Venkata Kumar
Ranch Hand

Joined: Apr 16, 2008
Posts: 110

The valid return values for doStartTag() function are SKIP_BODY and EVAL_BODY_INCLUDE. If the function doStartTag is not overriden then default value SKIP_BODY is returned.

The function doStartTag is overriden and the returned value 9911 is not valid return value. The default behaviour applied only when the function is not overridden.
From the Tomcat 6.x source code it seems that if the return type is not equal to SKIP_BODY then return type is considered as EVAL_BODY_INCLUDE

if the doStarTag returns EVAL_BODY_INCLUDE and if the custom tag has body then body is evalauted once.


Hence "hello" is displayed as output


SCJP 5.0, SCWCD 5, preparing for SCDJWS
Souvik Dasgupta
Ranch Hand

Joined: Sep 24, 2009
Posts: 77

are you using Tomcat 6.x?


Thanks and Regards, Souvik
SCJP, SCWCD, OCEJWSD
Royston Monteiro
Ranch Hand

Joined: Apr 25, 2008
Posts: 35

Venkat Divvela Yesterday 02:33:22 Subject: behaviour of doStartTag of TagSupport

--------------------------------------------------------------------------------

The valid return values for doStartTag() function are SKIP_BODY and EVAL_BODY_INCLUDE. If the function doStartTag is not overriden then default value SKIP_BODY is returned.
view plaincopy to clipboardprint?
# public int doStartTag() throws JspException{
# return 9911;
# }
# public int doStartTag() throws JspException{
# return 9911;
# }
The function doStartTag is overriden and the returned value 9911 is not valid return value. The default behaviour applied only when the function is not overridden.
From the Tomcat 6.x source code it seems that if the return type is not equal to SKIP_BODY then return type is considered as EVAL_BODY_INCLUDE

if the doStarTag returns EVAL_BODY_INCLUDE and if the custom tag has body then body is evalauted once.

view plaincopy to clipboardprint?
<mytag:ClassicTag >Hello</mytag:ClassicTag>
<mytag:ClassicTag >Hello</mytag:ClassicTag>
Hence "hello" is displayed as output


Thanks. That explains it.

Souvik Dasgupta Today 14:22:40 Subject: behaviour of doStartTag of TagSupport

--------------------------------------------------------------------------------

are you using Tomcat 6.x?


Yes, I am using Tomcat 6
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: behaviour of doStartTag of TagSupport
 
Similar Threads
Is this correct?
printing from doAfterBody in tag handler
Is returning invalid integer from doStartTag() is equivalent to returning EVAL_BODY_INCLUDE ?
doubt in doAfterBody
Edurardo Cobian's mock exam answer correct for Question No 25