• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HF Custom Tag question

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With reference to the HF book, the answer to question 9 at the bottom of chapter 10 (page 553) looks incorrect to me. If you agree with the book, can you please post a better explanation? Thanks.

Given:
10. public class BugTag extends BodyTagSupport {
11. public int doStartTag() throws JSPException {
12 // insert code here
13. }
14. }

Assume that the tag has been properly configured to allow body content. Which, if inserted at line 12 would cause the JSP code
<mytags:mytag>BodyContent</mytags:mytag> to output BodyContent>

The book marks the correct answer to be
B. return EVAL_BODY_INCLUDE;
and tells you that option C is invalid because it directs the body of the tag to a buffer which the tag does not process. ??

However, since the class is extending BodyTagSupport, the correct answer should be: (ref to page 536)
B. return EVAL_BODY_INCLUDE;
C. return EVAL_BODY_BUFFERED;
 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sandy, Not to worry!

In the real exam, you will have 'choose 1' (or) 'choose 2'.

Give first priority to EVAL_BODY_INCLUDE because that is simple to use.

However, if we use EVAL_BODY_BUFFERED, then we have to explicitly output the body content using writeOut and getEnclosingWriter methods.

But as you say, we can use both to output the body content.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
EVAL_BODY_BUFFERED

Request the creation of new buffer, a BodyContent on which to evaluate the body of this tag. Returned from doStartTag when it implements BodyTag. This is an illegal return value for doStartTag when the class does not implement BodyTag.
 
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Returning EVAL_BODY_BUFFERED won't print BodyContent to the output because this class only overrides the doStartTag() method and none of the rest....therefore the Question is perfectly alright
[ December 28, 2006: Message edited by: Sayak Banerjee ]
 
Sandy Shah
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for those who responded and helped clarify the issue. I now have a better understanding of buffered body content.

Sandy
 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No Sayak.The class is extending BodyTagSupport and not BodyTag which will have the default implementation of setBodyContent(BodyContent b),so both should be fine right?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic