Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

BodyTagSupport return values

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Christophe,

Here is the class

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
aha.. Working fine.

Thank you Christophe
Kathir
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic