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.
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%)
Joined: Apr 21, 2008
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.
Joined: Feb 03, 2009
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.
Joined: Apr 21, 2008
Hi, Uday Kumar. Thanks for your reply.
subject: BodyTagSupport's return value EVAL_BODY_BUFFERED