Attribute Directive
Declares attributes of custom actions defined in tag files. Used in tag files only.
JSP Syntax
<%@ attribute name="attribute-name" [ required="true | false" ] [ fragment="true | false" ] [ rtexprvalue="true | false" ] [ type="java.lang.String | a non-primitive type"] [ description="text" ] %>
<jsp:directive.attribute attributeDirectiveAttrList />
where attributeDirectiveAttrList is the same as the list for JSP syntax
XML Syntax
<jsp:directive.attribute attributeDirectiveAttrList />
where attributeDirectiveAttrList is the same as the list for JSP syntax
Examples
The Duke's Bookstore example includes a custom tag, called shipDate, that is defined in a tag file, shipDate.tag. The tag file includes an attribute directive that declares the shipDate tag's attribute, shipping:
<%@ attribute name="shipping" required="true" %>
Here is an example of the shipDate tag used in the bookreceipt.jsp page:
<sc:shipDate shipping="${param.shipping}" />
Description
The attribute directive allows the declaration of attributes for custom tags in tag files. This is analogous to the attribute element of a TLD file.
Attributes
name = "attribute-name"- The unique name of the attribute being declared. A translation error results if more than one
attributedirective appears in the same translation unit with the same name. A translation error results if there is anattributedirective with anameattribute equal to the value of thename-givenattribute of avariabledirective or thedynamic-attributesattribute of atagdirective in this translation unit.
- The unique name of the attribute being declared. A translation error results if more than one
required="true |false"fragment="true |false"- Whether this attribute is a fragment to be evaluated by the tag handler (
true) or a normal attribute to be evaluated by the container prior to being passed to the tag handler. If this attribute istrue:
- You do not specify the
rtexprvalueattribute. The container fixes thertexprvalueattribute attrue. - You do not specify the
typeattribute. The container fixes thetypeattribute atjavax.servlet.jsp.tagext.JspFragment.
- Whether this attribute is a fragment to be evaluated by the tag handler (
rtexprvalue="true| false"- Whether the attribute's value may be dynamically calculated at runtime by a scriptlet expression. Unlike the corresponding TLD element, this attribute defaults to true.
- Whether the attribute's value may be dynamically calculated at runtime by a scriptlet expression. Unlike the corresponding TLD element, this attribute defaults to true.
type="java.lang.String |a non-primitive type"- The runtime type of the attribute's value. Defaults to
java.lang.Stringif not specified. It is a translation error to specify a primitive type.
- The runtime type of the attribute's value. Defaults to
description="text"
