These tips and best practices apply to all code that utilizes the ALI Scripting Framework.
Use unique names for all forms and functions. Use the
GUID of a portlet to form 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. <pt:namespace pt:token="$$TOKEN$$" xmlns:pt='http://www.plumtree.com/xmlschemas/ptui/'/> <a onclick="doStuff$$TOKEN$$();" href="#">do stuffa onclick="doStuff$$TOKEN$$();" href="#">do stuff</a> <script> function doStuff$$TOKEN$$() { alert("hello"); } </script>Valid values for the token are 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. For details on adaptive tags, see About Adaptive Tags. |
|
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 gateway, see About Pagelets and the Gateway. | |
Check for ALI Scripting Framework support. The Scripting
Framework is a standard feature starting with version ALI 6.0 and
Ensemble 1.0. 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 { [scripting code here] } </script> |
|
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. | |
Do not assume that browsers will process script blocks/includes
added through the innerHTML property. Add all required JavaScript
to the page in advance:
|