Client-Side Developer’s Guide

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

The WLP Disc Framework

This chapter discusses the Dynamic Interface SCripting (Disc) framework. Sometimes used in combination with the WLP REST API, Disc provides a client-side JavaScript API to assist with developing rich, interactive portlets and portal applications. Disc helps you write Ajax-enabled portlets that enable rich, interactive portal web application features.

This chapter includes these topics:

 


What is Disc?

Disc provides a client-side, JavaScript, object-oriented programming framework for handling events, making asynchronous portlet updates, and for accessing portal context objects. Like their Java-based WLP API counterparts, Disc context objects encapsulate descriptive portal information, such as portlet positions within placeholders, titles, labels, and so on. The information returned in context objects can be used as parameters to REST commands to modify the portal. For instance, the WLP feature called placeable movement (drag and drop portlets) is implemented using Disc and REST features (see Enabling Placeable Movement in the Portal Development Guide).

Tip: Reference documentation for the Disc JavaScript API is provided on e-docs.

The Asynchronous Desktop Mode and DVT features both use Disc, as illustrated in Figure 3-1. If you enable either Asynchronous Desktop Mode or DVT for a portal desktop, Disc is implicitly enabled.

Figure 3-1 Features That Depend on Disc

Features That Depend on Disc

The DVT flag enables the placeable movement (drag and drop portlets) feature for the portal desktop. Asynchronous desktop rendering and placeable movement are both discussed in the Portal Development Guide.

 


Enabling Disc

To use Disc in client-side portal code, you have to enable it first. You can enable Disc in Workshop for WebLogic or in the WebLogic Portal Administration Console. You can also use Disc outside the context of a portal.

This section includes these topics:

What Enabling Disc Means

When Disc is enabled, you have access to the following WLP client-side development features:

Enabling Disc in Workshop for WebLogic

To enable Disc for a portal desktop in Workshop for WebLogic, set Disc Enabled to true in the desktop Properties view, as shown in Figure 3-2.

Figure 3-2 Enabling Disc in Workshop for WebLogic

Enabling Disc in Workshop for WebLogic

Note: Enabling either Asynchronous Mode or DVT implicitly enables Disc for a desktop.

Enabling Disc in the Administration Console

To enable Disc in the Administration Console:

  1. In the Portal Resources tree, select Portals and navigate to a desktop.
  2. Select the Details tab.
  3. Click Advanced Properties (Figure 3-3) and use the dialog to set Enable Disc to true.
  4. Figure 3-3 Enable Disc


    Enable Disc

Note: If you enable Asynchronous Mode or DVT, Disc is implicitly enabled.

Using Disc Outside of a Portal

The WLP Portlet Publishing feature uses Disc outside of a portal. Portlet Publishing lets you render portlets in any HTML page. For more information on Portlet Publishing, see Portlet Publishing.

 


Using Portal-Aware XMLHttpRequest to Retrieve Data from a Non-Portal Source

The standard XMLHttpRequest object, familiar to Ajax developers, can be used to update discrete amounts of data within a portlet. The Disc API class, bea.wlp.disc.io.XMLHttpRequest, is an extension of the standard XMLHttpRequest class. WLP’s XMLHttpRequest allows you to make asynchronous, incremental calls to the portal server, and supports portal features such as interportlet communication and WSRP. However, you can also use the portal-aware XHR in the same way you use a standard XHR. Like a standard XHR request, a portal-aware XHR request can be used from any JSP portlet page to retrieve any arbitrary data, which can then be inserted into the portlet.

Use Case

For an example use case, you could write a portlet that includes an auto-complete search form. When a user types text in the search field, the portlet sends portal-aware XHR requests to the server to retrieve suggestions for the user. In this process, the portlet UI does not refresh itself, except for the suggestions shown in the text field.

Example

In Listing 3-1, a portal-aware XHR object is instantiated and used to asynchronously retrieve data from a non-portal source. This code is intended to be embedded in a JSP page.

Listing 3-1 Using Portal-Aware XHR to Retrieve Data from a Non-Portal Source
<script type="text/javascript">
var dataUrl = 'data.json';
var xmlhttp = new bea.wlp.disc.io.XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
var data = eval('(' + xmlhttp.responseText + ')');
var table = document.getElementById('data');
for (var i = 0; i < data.length; i++) {
// insert rows into "data" table by referencing properties of
                // data[i] objects.
}
}
}
xmlhttp.open('GET', dataUrl, true);
xmlhttp.send();
</script>

 


Using Portal-Aware XMLHttpRequest to Update Portlets

Portal-aware XMLHttpRequest allows client-side JavaScript code to interact with the portal framework on the server on behalf of a portlet. When a portal-aware XHR call is made to the server, the request is processed by the portal, which decides what to do with the request. The portal may decide to invoke a given portlet and provide it with the appropriate context, such as user properties, portlet preferences, and request and response objects. Because the portal manages dependencies between portlets, interportlet communication is possible with portal-aware XHR.

Use Cases

Two use cases for using portal-aware XHR are:

As a developer, you have the option of using the WLP-specific XMLHttpRequest object (bea.wlp.disc.io.XMLHttpRequest) to update portal-specific content. When you make a request through this object, features such as IPC and WSRP are supported. For detailed information on the portal-aware XHR class, see the Disc API reference documentation on e-docs.

To enable portal-aware XHR in Workshop for WebLogic, follow the instructions in the section Enabling Disc in Workshop for WebLogic.

Example

Listing 3-2 is basically the same as Listing 3-1. The difference is that Listing 3-2 refers to a portlet as the source of the data. This example code is expected to be embedded directly in a JSP page.

Listing 3-2 Using Portal-Aware XHR to Update Portlets
<%@ taglib prefix="render" uri="http://www.bea.com/servers/portal/tags/netuix/render" %>
<render:jspContentUrl contentUri="/path/to/portlet/data.jsp" forcedAmpForm="false" var="dataUrl"/>

<script type="text/javascript">
var dataUrl = '${dataUrl}';
var xmlhttp = new bea.wlp.disc.io.XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
var data = eval('(' + xmlhttp.responseText + ')');
var table = document.getElementById('data');
for (var i = 0; i < data.length; i++) {
// insert rows into "data" table by referencing properties
                // of data[i] objects.
}
}
}
xmlhttp.open('GET', dataUrl, true);
xmlhttp.send();
</script>

 


Using Context Objects

Disc lets you work with portal context objects on the client, using JavaScript. Context objects encapsulate certain information about portal components. Context objects contain information about the following portal components:

Disc content classes are loosely representative of the server-side PresentationContext classes and serve a similar function in client-side programming. The set of context objects in the bea.wlp.disc.context module are described in detail in the Disc API reference documentation on e-docs.

Note: Only context objects for visible components are available; context objects for non-visible components such as books peer to the current book or hidden portlets are not available through the Disc APIs.

Using Context Objects

Disc context objects are generally available only after the entire HTML page has loaded. As a best practice, do not attempt to use context objects from inline script blocks. Instead, register an on-load handler that specifies interaction with context objects. For example, the code in Listing 3-3, when placed inline in a portlet JSP, results in an error:

Listing 3-3 Wrong Way to Access a Context Object
//portlet will be null
var portlet = bea.wlp.disc.context.Portlet.findByLabel("myPortletLabel");
var title = portlet.getTitle(); // error

However, if you add the same code in a Dojo (for example) on-load function, the code works as expected:

Listing 3-4 Recommended Way to Access a Context Object
dojo.addOnLoad(function() {
    var portlet = bea.wlp.disc.context.Portlet.findByLabel("myPortletLabel");
    var title = portlet.getTitle();
});

Listing 3-5 illustrates a simple debugging example. The best practice is to place this code in a render dependencies file. See Creating a Render Dependencies File for more information.

Listing 3-5 Simple Debugging Example
dojo.addOnLoad(function() {
var portlets = bea.wlp.disc.context.Portlet.getAll();
for (var i = 0; i < portlets.length; i++) {
bea.wlp.disc.Console.debug(portlets[i]);
}
});

Listing 3-6 presents another example that uses context objects.

Resources from render dependencies files are always included for a portlet regardless of mode or state (except for minimized, which is a special case). If a portlet has a general function that tries to inject content into a portlet that always runs when loaded from a render dependencies file (attached to an onload handler for example), the function should probably only try to do the content injection when the portlet is in “normal view” mode. Listing 3-6 is intended to be loaded from a render dependencies file.

Listing 3-6 Using Disc to Determine Portlet State
function createDataTables(label) {
    var portlet = bea.wlp.disc.context.Portlet.findByLabel(label);
    if (portlet.getWindowMode() == "view") {
        // retrieve data and create corresponding tables...
        if (portlet.getWindowState() == "maximized") {
            // create table with extended details
        }
        else {
            // create table with common details
        }
    }
}

 


The XMLHttpRequest Interaction Engine

The Disc module bea.wlp.disc.xie defines public APIs for Disc’s XMLHttpRequest Interaction Engine (XIE). XIE is the client-side foundation for Ajax-driven interactions with WebLogic Portal. XIE is also the platform on which various other Ajax-based, public Disc APIs are implemented, including:

The XIE API is divided into two main areas:

For more information on this classes described in this section, see the Disc API documentation on e-docs.

 


Event Handling

The bea.wlp.disc.xie.Events object contains the set of public, global events that are fired during XIE's WLP interaction lifecycle. The interaction lifecycle involves setting up and executing an Ajax request to the WLP server, receiving a response, and subsequently processing the response. WLP Ajax responses are encoded in an internal JSON format (the form of which is reserved and subject to change), and XIE manages the evaluation and handling of the body of these responses. The suite of public XIE events provides public access to key moments of interest during this lifecycle; listening code can use these event hooks to respond to or even influence the outcome of the interaction. For more information on this class, see the Disc API documentation on e-docs.

  1. OnPrepareUpdate – Fired when an interaction has been initiated, but before the request is made. This event can be cancelled; cancellation terminates the interaction without making the underlying request.
  2. OnHandleUpdate – Fired immediately after XIE receives the response, but before processing has begun.
  3. OnRedirectUpdate – Fired if the server is forcing the client to perform a redirect; processing will complete as soon as possible and then a client-side redirect is performed.
  4. Then, for each piece of response markup returned by the server, the following events are fired:
    1. OnPrepareMarkup – Fired before converting a response markup fragment into a DOM subtree; this event fires once for each markup fragment that was returned in the response.
    2. OnPrepareContent – Fired immediately after converting a markup fragment into a DOM subtree, but before doing additional processing (such as rewriting anchor hrefs and form actions); this event fires once for each markup fragment that was returned in the response.
    3. OnInjectContent – Fired immediately after injecting the fully processed (for example, rewritten) DOM subtree into the document, but before executing any scripts associated with that content; this event fires once for each markup fragment that was returned in the response.
  5. OnCompleteUpdate – Fired after XIE has completed all response processing for the interaction, including the execution of any scripts defined by the markup updated during the interaction
  6. OnError – Fired any time an error occurs during interaction processing; processing may or may not continue once an OnError event has fired.

Each event delivers a payload object to its listeners when the event is fired. The type and capabilities of each payload object differ from event to event. See the documentation for each individual event for more information about specific event payloads in the Disc API documentation on e-docs.

 


Logging

One way to implement logging is to use the Firebug logging model. For information on this model, see http://getfirebug.com/logging.html. Both Firebug and Firebug Lite provide a global Console object that you can use to monitor logging output.

Disc provides a Console object (bea.wlp.disc.Console) that replicates the API found in the Firebug Console object. You can use this object anytime Disc is available. For information on the Disc Console object, refer to bea.wlp.disc.Console in the Disc API documentation on e-docs.

Example

Listing 3-7 shows a simple example of how to set up a listener and send messages through the Console object. All messages logged to the Console are passed to each listener on the object. The listener function can be passed the following arguments when the debug call is made:

op
“debug”
args
[“label=”, “myPortlet”]

This configuration will output the following line of HTML text into a div named myConsoleOutput, which needs to have been previously defined somewhere on the page:

DEBUG: label=myPortlet
Listing 3-7 Simple Example: Setting Up a Console Listener
bea.wlp.disc.Console.addListener(function(op, args) {
    var output = document.getElementById("myConsoleOutput");
    output.appendChild(document.createElement("br"));
    output.appendChild(document.createTextNode(op.toUpperCase() + ": " +     args.join(",")));
});
// Sometime later... Assume myPortlet.getLabel() returns "myPortlet"
bea.wlp.disc.Console.debug("label=", myPortlet.getLabel());

  Back to Top       Previous  Next