| Author |
BodyTagSupport return values
|
Kathiresan Chinna
Ranch Hand
Joined: Aug 17, 2008
Posts: 115
|
|
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
Joined: Aug 17, 2008
Posts: 115
|
|
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14669
|
|
|
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 ?
|
[My Blog]
All roads lead to JavaRanch
|
 |
Kathiresan Chinna
Ranch Hand
Joined: Aug 17, 2008
Posts: 115
|
|
Hi Christophe, Here is the class
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14669
|
|
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
Joined: Aug 17, 2008
Posts: 115
|
|
aha.. Working fine. Thank you Christophe Kathir
|
 |
 |
|
|
subject: BodyTagSupport return values
|
|
|