Tag Library declarations in the Webapp DD


taglib*, <taglib (taglib-uri, taglib-location)>
ex:
<web-app>
    <taglib>
        <taglib-uri> http://www.jspinsider.com/jspkit/javascript </taglib-uri>
        <taglib-location> /WEB-INF/JavaScriptExampleTag.tld </taglib-location>
    </taglib>
</web-app>

Tag Library Descriptor

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

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

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

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

Interface/Class Method
Return
body-content
NOTE
Tag 
doStartTag()
SKIP_BODY
Must be “empty”  



EVAL_BODY_INCLUDE
JSP  



EVAL_BODY_BUFFERED
tagdependent 
Tag Handler must implement BodyTag

doEndTag()
SKIP_PAGE  




EVAL_PAGE  



setPageContext() 


First method to be called by container

setParent()


Second method to be called

setter methods       


If present then third call

getParent()
Tag       



release()       


Called in end, must be called , to release state
IterationTag extends Tag
doAfterBody()
EVAL_BODY_AGAIN
JSP
Body is again evaluated till it return SKIP_BODY.


SKIP_BODY 
JSP   

BodyTag extends IterationTag
doInitBody() 
EVAL_BODY_BUFFERED
tagdependent
This is called after setBodyContent() and before the first time body is evaluated.It will be called only if doST() returns EVAL_BODY_BUFFERED


Identify properly formatted custom tag usage in a JSP page.
Uses include:
·    An empty custom tag -     <msgBean:message/>
·    A custom tag with attributes  -  <msgBean:message attrName=”value” />
·    A custom tag that surrounds other JSP code -  <msgBean:message> <h1>This is the title</h1> </msgBean:message>
·    Nested custom tags-  <msgBean:message> <helloBean:sayHello/> </msgBean:message>

Identify valid return values for the following methods:
·    doStartTag - Tag.EVAL_BODY_INCLUDE, BodyTag.EVAL_BODY_BUFFERED, Tag.SKIP_BODY
·    doAfterBody – IterationTag.EVAL_BODY_AGAIN, Tag.SKIP_BODY
·    doEndTag – Tag.EVAL_PAGE, Tag.SKIP_PAGE
·    PageContext.getOut - javax.servlet.jsp.JspWriter


Identify the method in the custom tag handler that accesses:
·    A given JSP page's implicit variable
·    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() and getServletContext().

The following methods provide support for forwarding, inclusion and error handling:
forward(), include(), and handlePageException().

The methods related to attributes are:
setAttribute(), getAttribute(), removeAttribute() – deals page scope
findAttribute(), - looks in all scopes
int getAttributesScope() and 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.


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)



Tag Extension Classes

public abstract class BodyContent extends JspWriter {
// Constructor
  protected BodyContent(JspWriter e);
  // Methods
  public void clearBody( );
  public void flush( ) throws java.io.IOException;
  public JspWriter getEnclosingWriter( );
  public abstract java.io.Reader getReader( );
  public abstract String getString( );
  public abstract void writeOut(java.io.Writer out)
    throws java.io.IOException;
}

public interface BodyTag extends Tag {
  // Constants
  public static final int EVAL_BODY_TAG;
  // Methods
  public int doAfterBody( ) throws JspException;
  public void doInitBody( ) throws JspException;
  public void setBodyContent(BodyContent b);
}

public class BodyTagSupport extends TagSupport implements BodyTag {
  // Constructor
  public BodyTagSupport( );
  // Methods
  public int doAfterBody( ) throws JspException;
  public int doEndTag( ) throws JspException;
  public void doInitBody( );
  public BodyContent getBodyContent( );
  public JspWriter getPreviousOut( );
  public void release( );
  public void setBodyContent(BodyContent b);
}

public interface Tag {
  // Constants
  public static final int EVAL_BODY_INCLUDE;
  public static final int EVAL_PAGE;
  public static final int SKIP_BODY;
  public static final int SKIP_PAGE;
  // Methods
  public int doEndTag( ) throws JspException;
  public int doStartTag( ) throws JspException;
  public Tag getParent( );
  public void release( );
  public void setPageContext(PageContext pc);
  public void setParent(Tag t)
}

public class TagAttributeInfo {
  // Constructor
  public TagAttributeInfo(String name, boolean required,
    boolean rtexprvalue, String type, boolean reqTime);
  // Methods
  public boolean canBeRequestTime( );
  public static TagAttributeInfo getIdAttribute(TagAttributeInfo[] a);
  public String getName( );
  public String getTypeName( );
  public boolean isRequired( );
  public String toString( );
}

public class TagData implements Cloneable {
  // Constants
  public static final Object REQUEST_TIME_VALUE;
  // Constructor
  public TagData(Object[][] atts);
  public TagData(java.util.Hashtable attrs);
  // Methods
  public Object getAttribute(String attName);
  public String getAttributeString(String attName);
  public String getId( );
  public void setAttribute(String attName, Object value);
}

public abstract class TagExtraInfo {
  // Constructor
  public TagExtraInfo( );
  // Methods
  public TagInfo getTagInfo( );
  public VariableInfo[] getVariableInfo(TagData data);
  public boolean isValid(TagData data);
  public void setTagInfo(TagInfo tagInfo);
}

public class TagInfo {
  // Constants
  public static final String BODY_CONTENT_EMPTY;
  public static final String BODY_CONTENT_JSP;
  public static final String BODY_CONTENT_TAG_DEPENDENT;
  // Constructor
  public TagInfo(String tagName, String tagClassName,
    String bodycontent, String infoString, TagLibraryInfo taglib,
    TagExtraInfo tagExtraInfo, TagAttributeInfo[] attributeInfo);
  // Methods
  public TagAttributeInfo[] getAttributes( );
  public String getBodyContent( );
  public String getInfoString( );
  public String getTagClassName( );
  public TagExtraInfo getTagExtraInfo( );
  public TagLibraryInfo getTagLibrary( );
  public String getTagName( );
  public VariableInfo[] getVariableInfo(TagData data);
  public boolean isValid(TagData data);
  public String toString( );
}

public abstract class TagLibraryInfo {
  // Constructor
  protected TagLibraryInfo(String prefix, String uri);
  // Methods
  public String getInfoString( );
  public String getPrefixString( );
  public String getReliableURN( );
  public String getRequiredVersion( );
  public String getShortName( );
  public TagInfo getTag(String shortname);
  public TagInfo[] getTags( );
  public String getURI( );
}

public class TagSupport implements Tag, java.io.Serializable {
  // Constructor
  public TagSupport( );
  // Methods
  public int doEndTag( ) throws JspException;
  public int doStartTag( ) throws JspException;
  public static final Tag findAncestorWithClass(Tag from, Class klass);
  public String getId( );
  public Tag getParent( );
  public Object getValue(String k);
  public java.util.Enumeration getValues( );
  public void release( );
  public void removeValue(String k);
  public void setPageContext(PageContext pageContext);
  public void setId(String id);
  public void setParent(Tag t);
  public void setValue(String k, Object o);
}

public class VariableInfo {
  // Constants
  public static final int AT_BEGIN;
  public static final int AT_END;
  public static final int NESTED;
  // Constructor
  public VariableInfo(String varName, String className,
    boolean declare, int scope);
  // Methods
  public String getClassName( );
  public boolean getDeclare( );
  public int getScope( );
  public String getVarName( );
}