SECTION 12: DESIGNING AND DEVELOPING A CUSTOM TAG LIBRARY

Section 12
12.1 Identify the tag library descriptor element names that declare the following:
  • The name of the tag
  • The class of the tag handler
  • The type of content that the tag accepts
  • Any attributes of the tag
12.2 Identify the tag library descriptor element names that declare the following:
  • The name of a tag attribute
  • Whether a tag attribute is required
  • Whether or not the attribute's value can be dynamically specified
12.3 Given a custom tag, identify the necessary value for the bodycontent TLD element for any of the following tag types:
  • Empty-tag
  • Custom tag that surrounds other JSP code
  • Custom tag that surrounds content that is used only by the tag handler
12.4 Given a tag event method (doStartTag, doAfterBody, and doEndTag), identify the correct description of the methods trigger.
12.5 Identify valid return values for the following methods:
  • doStartTag
  • doAfterBody
  • doEndTag
  • PageConext.getOut
12.6 Given a "BODY" or "PAGE" constant, identify a correct description of the constant's use in the following methods:
  • doStartTag
  • doAfterBody
  • doEndTag
12.7 Identify the method in the custom tag handler that accesses:
  • A given JSP page's implicit variable
  • The JSP page's attributes
12.8 Identify methods that return an outer tag handler from within an inner tag handler.

Section 12 - Designing and Developing a Custom Tag Library

12.1 Identify the tag library descriptor element names that declare the following:

  1. The name of the tag <name>
  2. The class of the tag handler <tag-class>
  3. The type of content that the tag accepts <body-content>
  4. Any attributes of the tag

<attribute> 
    <name>username</name> 
    <rtexprvalue>true</rtexprvalue>
    <required>false</required>
    <type>String</type>
</attribute>

<!ELEMENT taglib (tlib-version, jsp-version, short-name, 
uri?, display-name?, small-icon?, large-icon?, description?, validator?, listener*, 
tag+) >

     <!ELEMENT tag (name, tag-class, tei-class?, body-content?, display-name?,
     small-icon?, large-icon?, description?, variable*, attribute*, example?) >

        <!ELEMENT variable ( (name-given | name-from-attribute), variable-class?, declare?,
        scope?, description?) >

     <!ELEMENT attribute (name, required? , rtexprvalue?, type?, description?) >

12.2 Identify the tag library descriptor element names that declare the following:

  1. The name of a tag attribute <name>
  2. Whether a tag attribute is required <required>
  3. Whether or not the attribute's value can be dynamically specified <rtexprvalue>

12.3 Given a custom tag, identify the necessary value for the bodycontent TLD element for any of the following tag types:

  1. Empty-tag empty
  2. Custom tag that surrounds other JSP code JSP(default, even if there's no body-content element)
  3. Custom tag that surrounds content that is used only by the tag handler tagdependent

12.4 Given a tag event method (doStartTag, doAfterBody, and doEndTag), identify the correct description of the methods trigger.

  1. doStartTag --Process the start tag for this instance
  2. doAfterBody --Process body(re)evaluation - repeat for iteration tag.
  3. doEndTag --Process the end tag for this instance. Used to clean up resources and add any closing tags to the output as necessary

12.5 Identify valid return values for the following methods:

  1. doStartTag
    
    Tag.EVAL_BODY_INCLUDE, 
    BodyTag.EVAL_BODY_BUFFERED,//for BodyTagSupport class
    Tag.SKIP_BODY
    
  2. doAfterBody
    
    IterationTag.EVAL_BODY_AGAIN, 
    Tag.SKIP_BODY
    
  3. doEndTag
    
    Tag.EVAL_PAGE, 
    Tag.SKIP_PAGE
    
  4. PageConext.getOut
    - javax.servlet.jsp.JspWriter

12.6 Given a "BODY" or "PAGE" constant, identify a correct description of the constant's use in the following methods:

  1. doStartTag
  2. doAfterBody
  3. doEndTag
                       doStart        doAfterBody       doEndTag
EVAL_BODY_INCLUDE        All
EVAL_BODY_BUFFERED   Body tag only
EVAL_BODY_AGAIN                        iteration
SKIP_BODY                All              All
EVAL_BODY_TAG                          deprecated 
EVAL_PAGE                                                 All
SKIP_PAGE                                                 All

12.7 Identify the method in the custom tag handler that accesses:

  1. A given JSP page's implicit variable
  2. The JSP page's attributes

A PageContext instance provides access to all the namespaces associated with a JSP page, provides access to several page attributes, as well as a layer above the implementation details. The following methods provide convenient access to implicit objects:

getOut(), 
getException(), 
getPage() 
getRequest(), 
getResponse(), 
getSession(),
getServletConfig()
getServletContext()

The following methods provide support for forwarding, inclusion and error handling:

forward(), 
include(), 
handlePageException().

The methods related to attributes are:

setAttribute(), 
getAttribute(), 
removeAttribute() - deals page scope
findAttribute(), - looks in all scopes 
int getAttributesScope()
getAttributeNamesInScope(int scope)

Note: TagSupport implements IterationTag which extends Tag. BodyTagSupport implements BodyTag which extends IterationTag.

getPreviousOut(), 
getBodyContent(), 
setBodyContent(), 
doInitBody() 
methods are defined in BodyTagSupport.

12.8 Identify methods that return an outer tag handler from within an inner tag handler.


Tag Tag.getParent()
Tag TagSupport.getParent()
Tag TagSupport.findAncestorWithClass(Tag from, java.lang.Class class) (A static method)

Return to top