This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes BodyTagSupport's return value EVAL_BODY_BUFFERED Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "BodyTagSupport Watch "BodyTagSupport New topic
Author

BodyTagSupport's return value EVAL_BODY_BUFFERED

Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi, I have a class that extends BodyTagSupport, the default return type of doStartTag() is EVAL_BODY_BUFFERED. If I invoke the tag with empty body, the container returns SKIP_BODY(because of it, the container executes doEndTag()). At what stage,(the lifecyle of BodyTagSupport) the container knows, the tag has no body, that's why I have to return SKIP_BODY? Thankyou.
udaykumar maddigatla
Ranch Hand

Joined: Feb 03, 2009
Posts: 69
Hi

If you didn't overide the doStartTag() method in your tag class, then the default value of doStartTag(i.e EVAL_BODY_BUFFERED in this case) will be invoked.

If we are sticking to the default value,then your class will execute the next method which is doInitBody() in this case,and doInitBody() will execute and compiler will execute the next method that is doAfterBody(). The default value of doAfterBody is SKIP_BODY.

so it will go the doEndTag() method and rest of the story continues.

Hope you understand.



SCJP 5.0(84%), SCWCD 5.0(97%), SCDJWS 5.0(98%)
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi, UdayKumar thanks for your reply. I think doInitBody() will be called after setBodyContent(). As far as I know, if the doStartTag() returns EVAL_BODY_BUFFERED, the container calls the pageContext's pushBody(), and the pushBody() creates BodyContent object,which is sub class of JspWriter(by encapsulating the body of the tag) and will return. Then the container sets the BodyContent via setBodyContent(BodyContent bc), after it will call doInitBody(), then the body is evaluated by the container. The whole above process will be happens when the tag invokes with the body and if the doStartTag() returns EVAL_BODY_BUFFERED.
If the tag is not invoked by body, and if we return EVAL_BODY_BUFFERED, the above process will not happen. It will directly executes doEndTag()(the doEndTag() tag will be execute only if the method returns SKIP_BODY). My question is at what stage, the container knows, that the tag has no body, that's why I (container), have to return SKIP_BODY. Thankyou.
udaykumar maddigatla
Ranch Hand

Joined: Feb 03, 2009
Posts: 69
hi,

what you said is correct. I didn't gone to too deep of setInitBody() ... all those stuff.

When we are creating the tag, in our .tag file we have to specify the behaviour of the tag in perspective of body by using the tag called


So by the time when container sees the tag it will try to see the syntax (i.e is tag followed what it specifies in .tag file).

So in our case the tag can contain the body. If body is there then body will processed. otherwise container will know by seeing the syntax of the tag.

Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi, Uday Kumar. Thanks for your reply.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BodyTagSupport's return value EVAL_BODY_BUFFERED
 
Similar Threads
doAfterBody()
ClassicTag issue
Return values of classic tag
HFSJ : page:553 Q:9
what is the default return value for doStartTag