• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BodyTagSupport return values

 
Kathiresan Chinna
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Actually I need to do something in doInitBody() method,
also the body content must be evaluated. So, I use BodyTagSupport.

1. I have a custom tag declared as



2. The class BodyTag1Handler extends BodyTagSupport.

3. In JSP



This is what happening:

1. If doStartTag() return EVAL_BODY_INCLUDE

Body is Evaluated and doAfterBody() is called.
setBodyContent() and doInitBody() is Not called.

This is OK

2. If doStartTag() return EVAL_BODY_BUFFERED

Body is Not Evaluated and doAfterBody() is Not called
But, setBodyContent() and doInitBody() is called.


The Lifecycle described in HFSJ page 563 is not happening in the case 2.

Can someone please tell am I missing anything ?

Thanks in advance
Kathir
 
Kathiresan Chinna
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have the book, so I don't know what the figure looks like. But I'm surprised that doAfterBody() is not called. Really ? Can you show what your tag handler looks like ?
 
Kathiresan Chinna
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Christophe,

Here is the class

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're falling into two common pitfalls :

1. You are overriding setBodyContent without setting the BodyContent anywhere. You need to at least call super.setBodyContent, or save the BodyContent into an instance variable. (If you don't use the BodyContent, it's not a problem)

2. The "page context's "out" is being pushed before doAfterBody is called. So when you use JspWriter out = pageContext.getOut();, you are not accessing the page's output stream, but the body buffer stream. That's why nothing is output to your client. You need to either output the body to the original "out", or get it directly with :



Here is a new version of your tag :


[ December 25, 2008: Message edited by: Christophe Verre ]
 
Kathiresan Chinna
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aha.. Working fine.

Thank you Christophe
Kathir
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic