aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes EVAL_BODY_BUFFERED - Yet again Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "EVAL_BODY_BUFFERED - Yet again" Watch "EVAL_BODY_BUFFERED - Yet again" New topic
Author

EVAL_BODY_BUFFERED - Yet again

Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
Hi all - I have a very simple tag handler.
It extends BodyTagSupport.
TLD has one tag, with <body-content> = JSP.
I override doAfterBody and only return super.doAfterBody();
I override doEndTag and only return super.doEndTag();
I also override doStartTag. When I return EVAL_BODY_INCLUDE, body evaluation occurs - I see what I believe is proper output - just data between my custom start/end tags.
However, if I return super.doStartTag() or EVAL_BODY_BUFFERED, I get no output, the data in the tag is not seen.

Is this right? If so, can someone please explain why?
Thanks, Guy
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
However, if I return super.doStartTag() or EVAL_BODY_BUFFERED, I get no output, the data in the tag is not seen.
Follow the API, it will answer your qstn....will wait for your version before I add mine.....maybe today evening.
- satya..........making you do your homework!!! so mean - right!


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
satya - I have confirmed that if EVAL_BODY_BUFFERED is returned from doStartTag, then:
setBodyContent is invoked properly (I do not override it)
doInitBody is invoked properly (I do not override it)
The API says:
If EVAL_BODY_BUFFERED is returned, setBodyContent() is invoked, doInitBody() is invoked, the body is evaluated, doAfterBody() is invoked, and then, after zero or more iterations, doEndTag() is invoked.

I do not see the 'body is evaluated' part happening.
?What am I missing?
Regards, Guy
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

I override doAfterBody and only return super.doAfterBody();
< snip >
I do not see the 'body is evaluated' part happening.

Your doAfterBody(...) is returning SKIP_BODY, by default.
- satya
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
But if, according to the API, the body is evaluated before doAfterBody(), which in his case returns SKIP_BODY, shouldn't the body evaluation still occur?
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
shouldn't the body evaluation still occur?
Yes, I beleive that the body is still evaluated. That's why when you return EVAL_BODY_INCLUDE from doStartTag(), the body is included. I haven't verified this with code, but relatively confident.
- satya
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
That's right - in both cases the body content is evaluated.
When you return EVAL_BODY_INCLUDE from doStartTag(), any content between the start and end tags just gets written back to the page as normal.
When EVAL_BODY_BUFFERED is returned from doStartTag(), the content is evaluated into a BodyContent object and not directly into the page. To see this content, you must extract it from the BodyContent object and write it out to the page.
This is a very powerful feature, and one that allows you to perform further manipulation before writing to the page.
Simon
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
Hi - Well, it is starting to make sense.
Regarding EVAL_BODY_INCLUDE the spec's use the phrase:
the body is evaluated and "passed through" to the current out

and regarding EVAL_BODY_BUFFERED they say just:
the body is evaluated

I have tests where I have overridden most/all of the methods, do some logging, and invoke the super method, followed by more logging. If the 'bodyContent' reference is not null, the actual contents are logged.
When EVAL_BODY_INCLUDE is returned, this (bodyContent) variable is always null.
When EVAL_BODY_BUFFERED is returned, it is not null after setBodyContent() is invoked.
So then ..... in doAfterBody (or perhaps doEndTag?) is where you would write the content out (after possible manipulation). Will test some of this shortly.
I agree a very powerful feature.
Guy
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
Originally posted by Guy Allard:
So then ..... in doAfterBody (or perhaps doEndTag?) is where you would write the content out (after possible manipulation).

Exactly
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
So then ..... in doAfterBody (or perhaps doEndTag?) is where you would write the content out (after possible manipulation). Will test some of this shortly
doEndTag, mostly.
Since the popBody() method is called after the doAfterBody() method completes and before doEndTag() is called.
Correct me if I am worng....please.
- satya
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
Originally posted by Guy Allard:

When EVAL_BODY_BUFFERED is returned, it is not null after setBodyContent() is invoked.

A clarification here - the bodyContent reference is null until setBodyContent is invoked. After that, the return value of bodyContent.getString() is an empty string until the start of doAfterBody, where it contains the expected data.
Guy
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
Originally posted by Madhav Lakkapragada:
So then ..... in doAfterBody (or perhaps doEndTag?) is where you would write the content out (after possible manipulation). Will test some of this shortly
doEndTag, mostly.
Since the popBody() method is called after the doAfterBody() method completes and before doEndTag() is called.
Correct me if I am worng....please.
- satya

That's right.
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
Hi Guys - after I have what I think is a reasonable example, this is very nice.
Run an experiment.
In doInitBody do:
bodyContent.getEnclosingWriter().print("Init<br>");
In doAfterBody do:
bodyContent.getEnclosingWriter().print(bodyContent.getString());
In doEndTag do:
bodyContent.getEnclosingWriter().print("End<br>");
Check the result in your browser!!
Regards, Guy
[ March 06, 2002: Message edited by: Guy Allard ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EVAL_BODY_BUFFERED - Yet again