concept portlet request in category java

appears as: portlet request, portlet request, portlet requests, A portlet request
Portlets in Action

This is an excerpt from Manning's book Portlets in Action.

A portlet container isn’t responsible for generating the portal page; it hands over the content generated by the portlets to the portal server, which aggregates the content and displays the portal page. Figure 1.10 shows the interaction between portal page, portal server, portlet container, and portlet instance when handling a portlet request.

Figure 1.10. The portal server and portlet container roles in handling a portlet request. The portlet container is responsible for invoking lifecycle methods and handing over the portlet content to the portal server. The portal server assembles the content from different portlets to generate the portal page.

If you have prior experience working with the Struts framework, you can closely relate the DispatcherPortlet here to the RequestProcessor class in the Struts framework. The DispatcherPortlet is at the heart of the Spring Portlet MVC framework and, like the RequestProcessor of the Struts framework, it’s responsible for coordinating all the request handling activities on receipt of a portlet request. It works with the other Spring Portlet MVC classes and interfaces that you saw in the Hello World portlet; figure 7.2 illustrates how they all interact.

Figure 7.2. Request processing in Spring Portlet MVC. The DispatcherPortlet acts as the front controller for each portlet and finds the handler mapped 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.

When a portlet request is received by the DispatcherPortlet (which is the portlet class) , it first attempts to find an appropriate handler for the request, and Spring Portlet MVC’s HandlerMapping type bean helps with this. Depending upon how you want to select a handler based on the portlet request, you’ll select an appropriate built-in HandlerMapping bean implementation. The Hello World portlet uses the PortletModeHandlerMapping bean which implements HandlerMapping and which selects an appropriate handler based on the current portlet mode . In the Hello World portlet, the PortletModeHandlerMapping maps the VIEW portlet mode to the HelloWorldController (see listing 7.5), so HelloWorldController is the handler for the render request received by DispatcherPortlet.

The requireSession property specifies whether the PortletSession is required to process the portlet request or not. This feature translates into the following piece of code:

if(requireSession){
  if(request.getPortletSession(false) == null) {
       throw new SomeException(...);
   } else {
       handleRenderRequestInternal(...);
   }
}

In this code, getPortletSession(false) returns the current PortletSession. If the request isn’t associated with a session, it returns null and the code can throw an exception. If getPortletSession(false) returns the current portlet session, the handleRenderRequestInternal or handleActionRequestInternal method of the subclass is invoked, depending upon whether the portlet request is an action or render request.

  • Specifies a default handler if no matching handler for the portlet request is found