Weblogic Portal - Refresh Single Portlet In Portal Desktop

Introduction:

              Over the past few years, Web 2.0 and Ajax have influenced the development of interactive Web applications. You can use Ajax to send asynchronous requests to a server without refreshing the full page. The result is very appealing to the end user because the Web application seems to react immediately, and the user’s experience is similar to what he or she sees when using a desktop application.

You can use the Single Portlet Refresh in use cases such as:

1) Refreshing only a specific part of the portlet’s markup using an asynchronous render request.

2) Updating portlet preferences using an asynchronous (action) request.


Previously, you could use Ajax in portlets only to access servers (for example, using servlets) to retrieve data.

This article introduces you to the new feature Single Portlet Refresh, tells you when and how to use it.

Single Portlet Refresh enables additional use cases. While you can use the servlet-based Ajax programming model for most use cases, it lacks the ability to directly connect to the portlet to use certain capabilities such as portlet preferences. Use cases that include updating portlet preferences are perfect candidates for using Single Portlet Refresh.

DISC

We use Dynamic Interface Scripting (Disc) framework to achive the above scenario. 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.

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.

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

Portal-Aware XHR (XMLHttpRequest) objects – If you are familiar with Ajax, then you know that XMLHttpRequest (XHR) objects are used to make asynchronous requests to the server. Because the browser’s native XHR object is designed to operate in the context of an entire web page, it does not work well in a portal environment where the page is composed of many separate portlets. Disc provides a portal-aware extension of XHR that makes requests that allow portlet markup to be updated asynchronously. The term portal-aware means that when the Ajax request is sent to the server from a portlet, the request can fire events, if required, and render its own view for further processing on the client.
Context Objects – Disc lets you work with context objects that encapsulate information about a portal, such as the portlet placeholder information, titles, labels, and so on. Context objects are generally read-only, and let you obtain information that you can use to create client-side interactivity and to pass to REST commands to update the portal.
XIE – The XHR Interaction Engine (XIE) provides the infrastructure for handling asynchronous requests, interportlet communication, and event handling. For instance, when asynchronous rendering is enabled for a desktop, XIE enables interportlet communication (IPC) to work correctly. When a request is made from a portlet, markup is automatically returned for that portlet and any portlet that is affected by the request through IPC.
Event Handling – Disc provides event handling mechanisms that work as callback functions and that can carry payloads. Events are tied to the “lifecycle” of asynchronous portlet requests. This means you can use events to trap information before a request is sent or before a response is processed by the client.

To enable Disc for a portal desktop in Workshop for WebLogic, set Disc Enabled to true in the desktop Properties view

enabling asynchronous


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.

The Below code is used to retrieve data from a Non Portal source using Portal-Aware XHR.


 <script type=”text/javascript”>   
   var dataUrl = ‘data.json’;  
   var xmlhttp = new bea.wlp.disc.io.XMLHttpRequest();  
   xmlhttp.onreadystatechange = function() {  
     if (xmlhttp.status == 200) {  
        var table = document.getElementById(‘data’);  
     }  
   xmlhttp.open(‘GET’, dataUrl, true);  
   xmlhttp.send();  
 </script>   

Listing 1-1

The Below code is used to to Update Portlets using Portal-Aware XHR

 <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.status == 200) {  
        var table = document.getElementById(‘data’);  
     }  
   xmlhttp.open(‘GET’, dataUrl, true);  
   xmlhttp.send();  
 </script>   

Listing 1-2

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 Portlets, Pages, Books etc. Disc context objects are generally available only after the entire HTML page has loaded.

How to Do Single Portlet Refresh

Now consider below code to refresh single portlet.

1) Ensure that DISC is enabled for portal desktop in workshop for weblogic. Also enable Asynchronous Mode for the portal desktop as shown in Figure 1.

2) Using DISC API try to retrieve the portlet context object

  var canvas = document.getElementById(“canvas”);  
  var portletContext = bea.wlp.disc.context.Portlet.findByElement(canvas);  

 

3) WLP 10.3.2 provides an refresh() method for Portlet Context Object. So you can call portletContext.refresh() which is used to refresh the portlet.

The complete code is provided below

 <jsp:root  
 version=”2.0″  
 xmlns:jsp=”http://java.sun.com/JSP/Page”  
 xmlns:render=”http://www.bea.com/servers/portal/tags/netuix/render”  
 >  
 <div id=”canvas” style=”text-align: center; margin: 8px;”>  
 This is test for Portlet Refresh  
 <button name=”changeLayout” onclick=”refresh();”>Refresh</button>  
 </div>  
 <script type=”text/javascript”>  
 function refresh() {  
 var canvas = document.getElementById(“canvas”);  
 var portletContext = bea.wlp.disc.context.Portlet.findByElement(canvas);  
 portletContext.refresh();  
 }  
 </script>   

Listing 1-3

Download Sample Project.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today