Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

doInitBody() method in Tag Handlers.

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a Tag Handler class that extends the BodyTagSupport class. I have over-ridden all the essential and main methods just to study the invocation process.
In the doInitBody() method, if I have a statment like :
- pageContext.getOut().write("Hello");
This statement does not result in printing out the String "Hello".
However it does work if I use -
- bodyContent.getEnclosingWriter().print("Hello");
The same is the case with the doAfterBody()..
Could anyone throw some light on this? Maybe I do not know some fundamental stuff related to JSP Custom Tags... so excuse me if this is a silly question
- Nutan
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, returning EVAL_BODY_BUFFERED from the doStartTag() method causes a new BodyContent object to be created. Behind the scenes, this replaces the "regular" JspWriter and it's this new BodyContent object that you get a reference to when you call getOut() on the PageContext.
Since the text that you write to a BodyContent object doesn't get "automatically" written to the page, this is why you don't see the output.
Hope that helps
Simon
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does your doStartTag() method return?
- satya
 
nutan prakash
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for the reply..

The doStartTag Returns EVAL_BODY_BUFFERED
- Nutan
 
A "dutch baby" is not a baby. But this tiny ad is baby sized:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic