AquaLogic User Interaction Development Guide

     Previous Next  Open TOC in new window   View as PDF - New Window  Get Adobe Reader - New Window
Content starts here

Creating Custom Adaptive Tags

The Adaptive Tag Framework allows you to create custom tags for use in pagelets and gatewayed pages.

The ATag class is the base class used to write custom tags

To implement a custom tag, follow the steps below.

  1. . To implement a new tag, you must have a tag library. A tag library is simply a .jar or .dll file with exactly one class that implements ITagLibraryMetaData.
    Java
    public static final TagLibraryMetaData LIBRARY = new TagLibraryMetaData
    ("Sample Tags", "sample", "This library provides sample tags.", 1.0);
    .NET
    public static readonly TagLibraryMetaData LIBRARY = new TagLibraryMetaData
    ("Sample Tags",  "sample", "This library provides sample tags.", 1.0);
  2. Create one public static final ITagMetaData member variable that provides the name and description of the tag. Create a public static final RequiredTagAttribute or OptionalTagAttribute member variable for every attribute that the tag supports. You can also use standard HTML and XML attributes; see Accessing Attributes in Custom Adaptive Tags.
    Java
    public static final ITagMetaData TAG;
    public static final RequiredTagAttribute MESSAGEATTRIBUTE;
    public static final OptionalTagAttribute LOCATIONATTRIBUTE;
    
    static
    {
    TAG = new TagMetaData("hellolocation", "This tag displays a hello message for the given location.");
    MESSAGEATTRIBUTE = new RequiredTagAttribute( "message", "The message to display for hellolocation tag", AttributeType.STRING); 
    LOCATIONATTRIBUTE = new OptionalTagAttribute("location", "The sample location attribute for hellolocation tag", AttributeType.STRING, "World");
    }
    .NET
    public static readonly ITagMetaData TAG;
    public static readonly RequiredTagAttribute MESSAGEATTRIBUTE;
    public static readonly OptionalTagAttribute LOCATIONATTRIBUTE;
    
    static HelloLocationTag()
    {
    TAG = new TagMetaData("hellolocation", "This tag displays a hello message for the given location.");
    MESSAGEATTRIBUTE = new RequiredTagAttribute( "message", "The message to display for hellolocation tag", AttributeType.STRING); 
    LOCATIONATTRIBUTE = new OptionalTagAttribute("location", "The sample location attribute for hellolocation tag", AttributeType.STRING, "World");
    }
    Type validation is performed by the tag framework automatically. If an optional attribute is not present in the HTML, the tag framework will use the default value. In the same code below, the optional attribute has a default value of "World.".
  3. Implement the DisplayTag abstract method. Use this method to create and display HTML. To display any HTML and tags defined within the tag, call ProcessTagBody and return the resulting HTML. The sample code below adds the "Hello" string with a user-specified location to an HTMLElement and returns it to be displayed.
    Java
    public HTMLElement DisplayTag()
    {
    String strLocation = GetTagAttributeAsString(LOCATIONATTRIBUTE);
    String strMessage = GetTagAttributeAsString(MESSAGEATTRIBUTE);
    HTMLElementCollection result = new HTMLElementCollection();
    result.AddInnerHTMLString(strMessage + strLocation + "!");
    return result;
    }
    .NET
    public override HTMLElement DisplayTag()
    {
    String strLocation = GetTagAttributeAsString(LOCATIONATTRIBUTE);
    String strMessage = GetTagAttributeAsString(MESSAGEATTRIBUTE);
    HTMLElementCollection result = new HTMLElementCollection();
    result.ddInnerHTMLString(strMessage + strLocation + "!");
    return result;
    }
  4. If the tag should not display any HTML contained within the tag, use the GetTagType method to return TagType.NO_BODY.
    Java
    public TagType GetTagType()
    {
    return TagType.NO_BODY;
    }
    .NET
    public override TagType GetTagType()
    {
    return TagType.NO_BODY;
    }
  5. Implement the Create abstract method to return a new instance of the tag.
    Java
    public ATag Create()
    {
    return new HelloLocationTag();
    }
    .NET
    public override ATag Create()
    {
    return new HelloLocationTag();
    }
The ATag class allows you to include a wide range of functionality in custom tags. For a full list of interfaces and methods, see the tagdocs. For links to all tagdocs, see API Libraries. For details on deploying your custom tag, see Deploying Custom Adaptive Tags.

  Back to Top      Previous Next