Previous article was about the life cycle of “Tag” interface, in this article i am going to explain the life cycle of “BodyTag” interface.
The BodyTag interface extends IterationTag by defining additional methods that let a tag handler manipulate the content of evaluating its body.
As per shown in Above figure, IterationTag extends Tag interface and adds one new method doAfterBody() that controls the reevaluation of its body.
doAfterBody() Process body (re)evaluation. This method is invoked by the JSP Page implementation object after every evaluation of the body into the BodyEvaluation object. The method is not invoked if there is no body evaluation.
If doAfterBody returns EVAL_BODY_AGAIN, a new evaluation of the body will happen (followed by another invocation of doAfterBody). If doAfterBody returns SKIP_BODY, no more body evaluations will occur, and the doEndTag method will be invoked.
In BodyTag, There is a new action method: doInitBody(), which is invoked right after setBodyContent() and before the body evaluation. This method is only invoked if doStartTag() returns EVAL_BODY_BUFFERED.
If EVAL_BODY_BUFFERED is returned, then a BodyContent object will be created (by code generated by the JSP compiler) to capture the body evaluation.
Example of Tag and BodyTag interface:
Tag Interface:
<up:userPicker multiSelect="true" />
BodyTag interface:
<up:userPicker multiSelect="true"> Select the User from UserPicker : </up:userPicker>
Next article : How to Create JSP Custom Tag – using Tag interface or TagSupport
Leave a Reply