wood burning stoves 2.0
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes doInitBody() method in Tag Handlers. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "doInitBody() method in Tag Handlers." Watch "doInitBody() method in Tag Handlers." New topic

doInitBody() method in Tag Handlers.

nutan prakash

Joined: Oct 28, 2000
Posts: 16
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

P.Nutan Prakash<br />SCJP2
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
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
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
What does your doStartTag() method return?
- satya

Take a Minute, Donate an Hour, Change a Life
nutan prakash

Joined: Oct 28, 2000
Posts: 16
Thanks for the reply..

The doStartTag Returns EVAL_BODY_BUFFERED
- Nutan
I agree. Here's the link: http://aspose.com/file-tools
subject: doInitBody() method in Tag Handlers.
jQuery in Action, 3rd edition