This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "doInitBody() method in Tag Handlers." Watch "doInitBody() method in Tag Handlers." New topic
Author

doInitBody() method in Tag Handlers.

nutan prakash
Greenhorn

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


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

Joined: May 10, 2000
Posts: 1913
    
    6
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

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


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
nutan prakash
Greenhorn

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