Thursday, January 26, 2012

Developing a portlet that shows real-time data using Comet (or Reverse Ajax)

In this post, I'll talk about the Book Catalog portlet example from Chapter 12 of Portlets in Action book that shows how you can create a portlet that shows real-time data.

You can download the source code for this example from here: http://code.google.com/p/portletsinaction/downloads/list.The name of the project is ch12_ResourceServing.

To know how to deploy the example, refer to the sample chapter 1 of Portlets in Action, which you can download for FREE from here: http://manning.com/sarin/

The following figures shows how the Book Catalog example portlet looks like:
Figure 1: The Book Catalog portlet uses a tabbed pane to divide up content in the user interface.
If a new book is added or removed from the catalog, a notification is displayed to the user.

Figure 2: Form for uploading a book’s TOC file. This form is displayed when the user clicks on the Upload link for a book


Figure 3: Form for adding a new book to the catalog. The form is displayed when the user selects
the Add Book tab or clicks the Add Book link shown on the catalog page (see figure 12.5).


The libraries used for developing the above example are: Dojo Toolkit, jQuery and DWR (Direct Web Remoting). The message 'Book Catalog data has been modified. Refresh' (refer figure 1) is displayed when other users of the Book Catalog portlet remove or add a new book to the catalog. This message is displayed using Comet (or Reverse Ajax) support available in DWR. When you use Comet, data is pushed by the server to the web browser. In polling, data is pulled at regular intervals from the server.

Saturday, January 14, 2012

Understanding handler interceptors in Spring Portlet MVC

In this post I've shown a figure from Chapter 7 of Portlets in Action which shows the role of handler interceptors in portlet request processing.
Handler interceptors are invoked before and after the execution of the handler. The preRenderHandle method is invoked before the handler execution, and the postRenderHandle method is invoked after the handler  execution. The afterRenderCompletion method is invoked after the postRenderHandle method of all the interceptors is executed.

Friday, December 9, 2011

Spring Portlet MVC basics

In this post I've shown one of the figures from Chapter 7 of Portlets in Action book, which depicts how Spring Portlet MVC framework works.


The DispatcherPortlet acts as the front
controller for each portlet and finds the handler mapped (which is HelloWorldController in the above diagram) to the request using HandlerMapping. The
result of executing a handler, ModelAndView, is used to resolve the actual view to be rendered, and
the request is dispatched to ViewRendererServlet for rendering.

Tuesday, November 29, 2011

Portlet request lifecycle phases

In this post I've shown figures from Portlets in Action book that depict action, render and resource request lifecycle phases.

Action and render request lifecycle phases

Figure 2.6 A portlet’s request-processing phases apply to incoming requests based on the request type (action or render). The portlet’s render method is always called to ensure that the updated portlet content is displayed by the web portal.



Resource request lifecycle phase (for handling AJAX use cases)

Figure 12.1 Ajax request handling. JavaScript in the portal page sends an
asynchronous request to a servlet or portlet component, which processes the
request and returns an HTML, XML, text, or JSON response to the browser.
JavaScript in the portal page makes use of the response data to update a part
of the portlet’s content.


Saturday, November 5, 2011

What is a portlet bridge?


[The above figure is from Chapter 14 of Portlets in Action book]
A portlet bridge acts as a bridge between portlet and web application environments. It translates requests from the portlet container into something that the web application can understand, and translates response from the web application that the portlet container can understand.

Thursday, November 3, 2011

Developing JSF and Wicket Portlets

If you want to develop portlets using JSF 2.0, then you can use Portletfaces bridge: http://www.portletfaces.org/projects/portletfaces-bridge


A portlet bridge is a component that sits between the portlet environment and a web
application. It’s responsible for bridging the differences between the portlet environment
and the environment in which the web application is designed to execute.


Chapter 14 of Portlets in Action shows how you can build JSF portlets using Portletfaces bridge or Wicket portlets using WicketPortlet class. It shows how you can first create a web application and then convert it into a portlet by making a few changes to it.