Question 5) Sun Certified Web Component

Posted on
Share on Google+Share on LinkedInShare on FacebookShare on RedditTweet about this on TwitterEmail this to someone

Objective : Building a Custom Tag Library

 

SubObjective : * Describe the semantics of the “Classic” custom tag event model when each event method (doStartTag, doAfterBody, and doEndTag) is executed, and explain what the return value for each event method means; and write a tag handler class.

Single Answer Multiple Choice

 

You are developing a set of custom tags to enable grouping of a set of books. The root element named <books> enables grouping of a set of books, and the element named <book> represents a single book with its ISBN number. The <books> and the <book> element implementation tags are BooksTag and BookTag, respectively, and they extend the BodyTagSupport class. Which course of action will enable you to access the ISBN number of each book from the parent tag <books>?

 

 

  1. Create the addISBN() method in the BooksTag, and use the doStartTag() method to return the EVAL_BODY_BUFFERED constant. In the doStartTag() method of BookTag, call the super.getParent() method, cast it to BooksTag, and call the addISBN() method.
  2. Create theaddISBN()method in theBookTag, and use thedoStartTag() method to return theEVAL_BODY_BUFFEREDconstant. In thedoStartTag() method ofBooksTag, call thesuper.getParent() method, cast it toBookTag, and call theaddISBN() method.
  3. Create theaddISBN()method in theBooksTag, and use thedoEndTag() method to return theEVAL_BODY_BUFFEREDconstant. In thedoEndTag() method ofBookTag, call thesuper.getParent()method, cast it toBooksTag, and call theaddISBN() method.
  4. Create theaddISBN()method in theBooksTag, and use thedoEndTag() method to return theEVAL_BODY_BUFFERED constant. In thedoAfterBodyTag() method of theBookTag, call thesuper.getParent() method, cast it toBooksTag, and call theaddISBN() method.

 

 

 

Answer:
A. Create the addISBN() method in the BooksTag, and use the doStartTag() method to return the EVAL_BODY_BUFFERED constant. In the doStartTag() method of BookTag, call the super.getParent() method, cast it to BooksTag, and call the addISBN() method.

Tutorial:
You should create the addISBN() method in BooksTag and use the doStartTag() method to return the EVAL_BODY_BUFFERED constant. In the doStartTag() method of the BookTag, call the super.getParent() method, cast it to BooksTag, and call the addISBN() method. The doStartTag() method of the TagSupport class is invoked by the JSP page implementation object to process the start tag. The doStartTag() method can be used to return the EVAL_BODY_BUFFERED constant to enable the evaluation of the body content. The super.getParent() method is called to obtain the parent tag handler of the superclass of the BookTag class.

 

The option that contains the method call super.getParent() in BooksTag is incorrect because it should be called in BookTag.

 

The option that contains the method call doEndTag() in the BooksTag is incorrect because you should return the value EVAL_BODY_BUFFERED for a doStartTag() and not for the doEndTag() method.

 

The option that contains the method call doEndTag() in the BooksTag and BookTag is incorrect because you should invoke the method super.getParent() from the doStartTag() method and not from the doEndTag() method.

Reference:
1. The J2EE 1.4 Tutorial, Chapter 16: Scripting in JSP Pages, Programming Tags That Accept Scripting Elements, Tag with Bodies, http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPAdvanced8.html#wp72582
2. Java 2 Platform Enterprise Edition v1.4, Package javax.servlet.jsp.tagext, BodyTagSupport, http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/jsp/tagext/BodyTagSupport.html

 

These questions are derived from the Self-Test Software Practice Test for 310-081 – Sun Certified Web Component Developer for J2EE Platform 1.4 .

Share on Google+Share on LinkedInShare on FacebookShare on RedditTweet about this on TwitterEmail this to someone
cmadmin

ABOUT THE AUTHOR

Posted in Archive|

Comment:

Leave a comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>