• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

when do you use doAfterBody() or doEndTag() ??

 
Joe Man
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm confused when do you use doAfterBody() or doEndTag()?
When i extends TagSupport class, i use the doAfterBody() to process the content body. Then when do you use doEndTag()?
Why are these two methods doAfterBody() and doEndTag() exists in TagSupport and BodyTagSupport classes?
Thanks for your help..
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, imagine that the body content of a custom tag can be evaluated more than once. For example, you might have an loop tag as follows:

First, the doStartTag() method is called. Following this, (and provided that EVAL_BODY_INCLUDE was returned), the body content inside the tag is evaluated. The doAfterBody() method is then called after the body content has been evaluated.
Depending on how the tag is written, the body content might be evaluated more times, with more subsequent calls to the doAfterBody() method.
Finally, doEndTag() is called.
Basically, you can have the following happen (depending on the return values for your lifecycle methods):
(1) doStartTag()
(2) evaluate body content
(3) doAfterBody()
(.) evaluate body content
(.) doAfterBody()
(n) doEndTag()
The key difference is that doEndTag() is only called once, while doAfterBody() can be called a number of times.
There are some great activity diagrams in my new book that explain this in much, much more detail, along with lots of examples of how to use the Tag, IterationTag and BodyTag interfaces.
Hope that helps
Simon
[ May 08, 2002: Message edited by: Simon Brown ]
 
Joe Man
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Simons!
That help alot.
Here is my thought. Whenever i want to modified bodyContent, I need to extends the BodyTagSupport class and override the doStartTag(), doAfterBody(), or doEndTag(). Is that correct?
Also, based on the method return value of , EVAL_BODY_INCLUDE, EVAL_BODY_TAG, EVAL_BODY_AGAIN, SKIP_BODY, EVAL_BODY_BUFFERED..The method gets called or not.
When does EVAL_BODY_BUFFERED should occur?

Thanks..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic