Strategy ONE
AnchorTag Interface
The AnchorTag interface is used to create each link exposed in MicroStrategy Web products. It represents an HTML anchor tag, <a>, and provides support to set basic anchor tag attributes, such as “target” and “href”, as well as attributes to execute JavaScript on certain JavaScript actions, such as “onclick” or “onchange”.
The AnchorTag interface defines a set of methods that allow you to get and set:
-
the event associated with the anchor tag
-
the event information that is to be included in the anchor tag
-
whether to treat the event as an IFrame event
-
a string of parameter information
-
the amount of child state information to be included in the link
-
the hash value that is to be appended at the end of the "href" attribute
An AnchorTag is created by a transform using the generateAnchor() method. You can customize an AnchorTag by extending a transform and overriding the generateAnchor() method in the transform. You can perform the following customizations to the anchor tag, and thus to the links generated by that transform:
-
add extra parameters to the anchor tag.
-
set the value of a basic attribute, such as the target page, in the anchor tag.
-
set the value of an attribute, such as "onclick" or "onmouseover", to execute JavaScript when the corrresponding JavaScript action is triggered.
To add parameters to an anchor tag, you use the Parameter Builder Infrastructure.
The code sample shown below illustrates how to add an extra parameter (filterPreprocessingParam), set a basic attribute value (target= "filterPreprocessingPage"), and add JavaScript code that performs some preprocessing on filters when the user clicks on the FOLDER_EVENT_BROWSE event in a custom transform called FolderViewTransformWithJSPreprocessing. These changes are applied to all of the anchor tags generated by the custom transform, and thus to all links created for pages rendered by styles that use the custom transform. By default, FolderViewTransform is used by styles that render the Folder Browsing page. Since it extends FolderViewTransform, FolderViewTransformWithJSPreprocessing is also used by the same styles.
public classFolderViewTransformWithJSPreprocessingextends FolderViewTransform {
/**
* Creates a <code><a></code> tag from the EventManager.
* @param event WebEvent
* @return AnchorTag
*/
public AnchorTag generateAnchor (WebEvent event) {
//call super to inherit default parameters and attributes from the parent transform
AnchorTag result = super.generateAnchor(event);
//Add a new parameter to the URL
result.getParameterBuilder().addParameter("filterPreprocessingParam", "value");
//Set the target to a new page
result.setAttribute(EnumHTMLTags.ATT_TARGET,"filterPreprocessingPage");
//Set the 'onclick' attribute on the anchor tag to add JavaScript code
//JavaScript code will be added only for filters.
if (event.getID() == EnumFolderBeanEvents.FOLDER_EVENT_BROWSE) {
result.setAttribute(EnumHTMLTags.ATT_ONCLICK, "return alert('Add code to process filter here...');");
//Developers can set other attributes such as:
//ATT_ONCLICK = "onclick"
//ATT_ONSUBMIT = "onsubmit"
//ATT_ONCHANGE = "onchange"
//ATT_ONKEYUP = "onkeyup"
//ATT_ONMOUSEOVER = "onmouseover"
//ATT_ONMOUSEOUT = "onmouseout"
}
return result;
}
}
You need to compile your custom transform and place the class file in your custom classes folder. Refer to Implementing custom class files for instructions on using the compiled class files.
To implement the customization described above, you need to change the Style Catalog Configuration file so that your custom transform is used by styles that render the Folder Browsing page. You need to change the FolderStyleIcon and FolderStyleList styles in the Style Catalog Configuration file, as shown below:
<Style description="Style: Display Folder in icon view" name="FolderStyleIcon" transform="FolderViewTransformWithJSPreprocessing">
<Style description="Style: Display Folder in list view" name="FolderStyleList" transform="FolderViewTransformWithJSPreprocessing">
After these changes are made, all links generated on the Folder Browsing page include your customizations.
See also
