Accessing Attributes in Custom Adaptive Tags
To access attributes used in a custom tag, use one of the GetTagAttribute* methods.
All basic data types are supported as attributes (defined
in the AttributeType class), including boolean,
char, double, int, long and string. The "pt:" attributes specify the
logic for the tag, while any non-pt attributes specify the behavior
of the resulting HTML tag. Non-pt attributes are only applicable in
tags that output a simple HTML tag.
- To access pt attributes, use the appropriate GetTagAttributeAs* method using the attribute name. A method is provided for each supported
attribute type, e.g., GetTagAttributeAsLong. The GetTagAttribute method is provided for backwards
compatibility and should not be used.
- First, define the attribute: MODE = new OptionalTagAttribute("mode",
"Turns debug mode on and off.", AttributeType.BOOLEAN, "true");
- Then, access the attribute in the DisplayTag method:boolean bNewDebugMode = GetTagAttributeAsBoolean(MODE);
- To access non-pt (XML/HTML) attributes, use the GetXMLTagAttribute method using the attribute name, or GetXMLTagAttributesAsString to retrieve all non-pt attributes.
result.AddInnerHTMLElement(new HTMLGenericElement("<a
href=\"" + GetHREF() + "\" " + GetXMLTagAttributesAsString() + ">"));
The ITagMetaData, RequiredTagAttribute, and OptionalTagAttribute objects pre-process
tag attributes (presence, correct type, and default values). If the
required attributes are not correct, an error is logged and the tag
and its children are skipped. An HTML comment describing the tag and
error is displayed instead.