Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doInitBody() method in Tag Handlers.

 
nutan prakash
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
 
Simon Brown
sharp shooter, and author
Ranch Hand
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
 
Madhav Lakkapragada
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic