![]() |
Michael Gilfix Online |
Navigation |
Using AJAX for JSR168 Inter-Portlet CommunicationMost articles around use of AJAX and JSR168 Portlets tend to focus on how AJAX techniques can be used to provide more dynamic visual display capabilities to Portlets. However, AJAX techniques (particularly the use of For those not familiar with Portlets, think of a Portlet as providing the graphical content for a portion, or visual unit, of a web page. The Portlet's sole responsibility is to render that unit of display for the page. Page content is assembled through a process called aggregation; each page has a notion of layout (typically expressed either as a JSP or in XML format) and a Servlet-like method on each Portlet is invoked by the container in order to render each piece of the aggregated page. The bare-bones Portlet container provided with WAS 6.1 does not provide aggregation capabilities. This must be done by a fronting JSP or Servlet. More advanced Portlet containers provide other capabilities, such as navigation between pages of content, filtering of content according to user roles, and even personalization of content. The basic idea behind Portlet approach (as for many other similar systems, including the Drupal system used for this blog is a sort of UI componentization, allowing reuse of visual content and function, and promoting separation in the backing code. Portlets are intended to be mixed and matched to construct page content, either directly by the users or by the administrators of the page. Sometimes, Portlets are provided in groups that are intended to work together to provide more advanced visual display. This approach still allows the user to have control of layout and visual elements via the Portlet container, and still promotes reuse of content and capability in the code. So, how to enable AJAX techniques with JSR168 Portlets? The best article I've found on the subject is from the a Sun Developer Network article. Here's a summary of the technique described in the article: each Portlet has an associated HTTP Servlet component that handles the AJAX communication. On load of the page, content is aggregated or generated using the usual Portlet techniques. The generated content typically has some visual element, such as a button, or Javascript code that calls the AJAX function which makes an XML HTTP request to the Servlet. The Servlet then typically sets some context information in the HTTP session based on the Javascript request before dispatching the request directly to the JSR168 Portlet code in order to render the dynamic content. The implementation architecture looks like this:
![]() Reproduced from Greg Ziebold and Jai Suri's article This technique is an excellent way to approach inter-Portlet communication in a Portable manner. It pushes the coupling of the Portlets out to the client, rather than relying on non-standardized Portlet techniques. In addition, it avoids requiring a page refresh when one Portlet updates another. An example of inter-Portlet communication might be when you have one Portlet that serves a filter for the content in another. Perhaps this was done to allow reuse of the filter UI on multiple pages. When the user updates the filter, it can result in an AJAX request that applies the new filter to the other portlet on the page, without requiring a page refresh. In addition, it also preserves portability between containers. |
SearchRecent blog posts
|