Pagelet and Portlet Development: Adaptive Pagelets

ALI Scripting Framework

The ALI Scripting Framework is a client-side JavaScript library that provides services to portlets and hosted gatewayed pages. (For details on the gateway, see Portal to Remote Server Communication). The Portlet Communication Component (PCC) is contained within the Scripting Framework.

These concepts also apply to pagelets deployed in Ensemble; a portlet is a pagelet designed for use in the ALI portal.

The ALI Scripting Framework allows portlets to:

For a full list of classes and methods, see the JSPortlet API documentation. To download the sample code referenced in this section, see the ALI Scripting Framework Samples in dev2dev code share.

Best Practices

The following best practices apply to all code that utilizes the ALI Scripting Framework.

Forms and functions must be uniquely named.  You must use the GUID of a portlet when forming unique names and values to avoid name collisions with other code on the page.

You can append the portlet ID using the pt:namespace and pt:token tags, as shown in the code below. (For details on Adaptive Tags, see Adaptive Pagelets: Using Adaptive Tags.)

<pt:namespace pt:token="$$TOKEN$$" xmlns:pt='http://www.plumtree.com/xmlschemas/ptui/'/>
<a onclick="doStuff$$TOKEN$$();" href="#">do stuff</a>
<script>
   function doStuff$$TOKEN$$() {
     alert("hello");
   }
</script>

Valid values for the token must be in the ASCII range 0x21 to 0x7E, excluding "<" (0x3C). The scope of the token runs from the tag defining it to the end of the file; you cannot use a token prior to defining it. A second pt:namespace tag with a different token redefines it; two tokens cannot be defined at the same time.

Gateway all URLs. You cannot make a request to a URL whose host/port differs from that of the calling page. All URLs requested through JavaScript must be gatewayed. For details on the portal gateway, see Portal to Remote Server Communication. For instruction on configuring gateway settings, see ALI Portlet Configuration and Ensemble Pagelet Configuration.

Check for ALI Scripting Framework support. The Scripting Framework is a standard AquaLogic Interaction feature starting with version 6.0. (The PCC component is installed with versions 4.5 and 5.x.) Earlier versions of the portal can be updated to support the ALI Scripting Framework with a JavaScript plug-in. For information, see the ALUI Developer Center on dev2dev.

It is good practice to include code that determines whether or not the component is present. Ideally, your portlet should be able to handle either situation. The simplest solution is to precede your code with an If statement that alerts the user if the ALI Scripting Framework is not supported.

<script>

if (PTPortlet == null)
{
if (document.PCC == null)
{
alert("This portlet only works in portals that support the ALI JSPortlet API or Portlet Communication Component (PCC). The portlet will be displayed with severely reduced functionality. Contact your BEA Administrator.");
}
}
else
{

[code here]
}
</script>

Note: Before version 5.0 of the portal, the PCC component was called the GCC (Gadget Communication Component). The document.GCC object is still supported in version 5.0.

Always close all popup windows opened by a portlet when the portal window closes. The ALI Scripting Framework can be used to close popup windows using the onunload event.
 

Browsers might not process script blocks/includes added to the page through innerHTML property. You must add all required JavaScript to the page in advance:

  • IE: Add the defer attribute to the script tag.

  • Netscape: Use RegExp to parse the response and look for the script, then eval it.

Next: Session Preferences