• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

doAfterBody() is not executed using BodyTagSupport

 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


In TLD
<body-content>scriptless</body-content>

In jsp i using tag as shown below
[code]
<mine:classic >
body of tag
</mine:classic >
[code]

Output is
doStartTag()doEndTag()

Above CTag class extends BodyTagSupport.
In above class doAfterBody() is not executed.i dont know why.

Please Help
Thanks
 
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
change the doAfterBody() to :-



However, if doStartTag() returns EVAL_BODY_BUFFERED, the JSP container
takes a different course of action. It first creates an instance of the BodyContent
class. The BodyContent class is a subclass of JspWriter and overrides all
the print and write methods of JspWriter to buffer any data written into it rather
than sending it to the output stream of the response. The JSP container passes the
newly created BodyContent instance to the tag handler using its setBodyContent()
method, calls doInitBody() on the tag, and finally evaluates the body of
the tag, filling the BodyContent buffer with the result of the body tag evaluation.

 
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nice bit of info....
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, needed one clarification....can't you use bodyContent.print() directly instead of
JspWriter out = bodyContent.getEnclosingWriter();
out.print();
I came across the former one in Mikalai Zaikin's notes...awaiting your reply!!!
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this


Every thing we write using JspWriter will be buffered to BodyContent.
So we must use JspWriter out = bodyContent.getEnclosingWriter() to write something to the output.
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Sreeraj...but if you replace the whole class with the one given below, it still works...that's what I was tryin' to say......please check this as well...you can try it out...



Also, I didn't understand one thing....despite the BodyTagSupport class providing an implicit bodyContent field, why did Gowher add one explicitly to hide the implicit one...I don't find any significant reason
[ December 09, 2006: Message edited by: Sayak Banerjee ]
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sayak i didn't get your question.
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My question was whether it's really required to get an output stream by calling getEnclosingWriter() on the bodyContent object just for the purpose of sending the data to the output stream of the response....I mean you could just do it using bodyContent.print() from doAfterBody() or doInitBody()(as shown in the code shown by me above)....the starter of the thread just wanted to achieve this I guess
[ December 09, 2006: Message edited by: Sayak Banerjee ]
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you checck the output?
What is the output of your code?
Please wright it down here.
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OUTPUT : doStartTag()doInitBody() !!body of tag!! doAfterBody()doEndTag()

In jsp i using tag as shown below

[ December 10, 2006: Message edited by: Sayak Banerjee ]
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sayak, i am also confused. Let me try it out.

If anyone knows please give us a clear picture.
 
Yeah, but is it art? What do you think tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic