Weblogic Portal - Refresh Single Portlet In Portal Desktop
By Murali Veligeti on Aug 03, 2012
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.
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
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.
The Below code is used to to Update Portlets using Portal-Aware XHR
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