Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EVAL_BODY_BUFFERED - Yet again

 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Guy Allard
Ranch Hand
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic