Wednesday, November 30, 2011

Resource serving

The resource serving feature provides the ability for a JSR 286 portlet to serve a resource.
Portlets can create two different kinds of resource links in order to serve resources:


1. Direct links to the resource in the same portlet web application. These links are constructed by the portlet and encoded with the PortletResponse.encodeURL() method. (This method might not return a valid URL. And direct links are not guaranteed to pass through the portal server and will not have the portlet context available. Direct links should be used for use cases where the access to the portlet context and access through the portal is not needed, as they are more efficient than resource serving requests via resource URLs through the portal.)
2. Resource URL links pointing back to the portlet. Via these links the serveResource method of the ResourceServingPortlet interface is called and the portlet can serve the resource. Thus resources served via resource URLs may be protected by the portal security and can leverage the portlet context. Static resources should still be served with direct links in order to allow portal applications to configure and optimize static resource serving in a consistent manner.
(Ref: JSR286 portlet specification, Click here to download the full specification.)

Event

JSR 286 portlet has introduced the event feature in it earlier in JSR 168 portlet spec, the only way to achieve eventing between portlets was through a portlet session. This was possible between portlets that are in the same web application. But in JSR defines a lifecycle for events, so that eventing is possible between portlets that are in different web applications.
(Ref: JSR286 portlet specification, Click here to download the full specification.)

Public render parameters

The JSR 286 portlet specification has introduced the Public render parameters concept: which allow portlets to share parameters with other portlets. That means we can achieve the Coordination between Portlets through the Public render parameters. Basically in JSR 168, the render parameters set in processAction is only available in the render of the same portlet. But in JSR 286 with the Public Render Parameters feature, the render parameters set in the processAction of one portlet will be available in render of other portlets also.
Following are the steps to create portlets that use the public render parameters:
Step-1. We will declare the render parameters to be shared in the portlet.xml file by setting the public render parameters at the portlet application level.
……

. . .


product-id

……
Step-2. Now specify the render parameter that the portlet would like to share in the portlet section.
……..

......
product-id


. . .
product-id

. . .

Strep-3 And now finally set the render parameter in the processAction() method:
public class ProductsPortlet extends GenericPortlet {
. . .
public void processAction(ActionRequest req, ActionResponse res) throws IOException, PortletException {
. . .
res.setRenderParameter("product-id", product);
}
. . .
}

Enjoy coding :-)

Monday, November 14, 2011

Difference between PortletConfig.getInitParameter() and PortletContext.getInitParameter()

  • Context initialization parameters are defined in the web.xml file. They share the same context space as Servlets and JSPs belonging to the same application and we can get them using PortletContext.getInitParameter() method.
  • Portlet-wide initialization parameters are defined in the portlet.xml file and we can get them using PortletConfig.getInitParameter() method.

Enjoy coding :-)