Fundamentals of Liferay Portlets - part 2

1. Difference between JSR-168 & JSR-286

Java Portlet spefication168 (v1.0) has very basic portlet porgramming model and had lot of limitations for portlet development. Java Portlet spefication286 (v2.0) was developed to overcome the shortcomings on v1.0 specs(JSR 168) such as:
  • 1. Inter portlet communicaiton (IPC) - IPC through events and public render parameters
  • 2. Support for WSRP 2.0
  • 3. Public render paremeters - Allows portlets to share parameters with other portlets.
  • 4. Portlet filters and listeners.
  • 5. Resource serving - Provide ability for portlets to server a resource
  • 6. AJAX support

2. Life cycle of portlet

  • init() - Initializes the Portlet
  • processAction() - process input from a user action.
  • render() - Renders the content output.
  • destroy() - Cleans up the portlet

3. How is  Inter portlet communication achieved in Liferay?

The Client side events mechanism

This is a new mechanism introduced in Liferay v5.0 and provides a very lightweight and decoupled mechanism to communicate portlets purely in the browser through a JavaScript events mechanism.
A full wiki article covers this topic in detail: Client-side Inter-Portlet Communication]

AJAX way

The pattern is: You make an ajax call from one portlet and provide this portlet with id in another portlet. When you have an answer from the ajax call you update the div with the information you got.
It would be convenient to route the calls through a container object. Whenever, a portlet is added or removed, it needs to register/un-register itself to the container. The container would refer to the portlet through it's id and the reference to the DIV element.

Session variables sharing

Another way is to store variables in the session and make them sharable for portlets. This way you can put stuff into session and display different things based on the information in the session. Look here: Sharing session variables

Use Liferay portlet url tag

Proprietary portlet url tag that allows you to target one portlet to another (cross-linking). It looks something like this

Where "xxx" is the xxx of the portlet as defined in the portlet.xml file. Note that it also needs to include the WAR reference if it is in a portlet war.
e.g. A war named "sample-struts-liferay-portlet" having a portlet with the name "sample_struts_liferay_portlet" will have an fully qualified name as:
sample_struts_liferay_portlet_WAR_samplestrutsliferayportlet

Furthermore, if the portlet is instanceable (true in liferay-portlet.xml) it will contain an instance identifier like so: _INSTANCE_im3I making the full name:
sample_struts_liferay_portlet_WAR_samplestrutsliferayportlet_INSTANCE_im3I

The end result is a portlet tag like so:


You can also look at this topic for discussion and details.
  • 4. What is the difference between organization & communities ?
  • Users belong to an organization which means that the org admin is able to edit her profile. OTOH users join a community which means that the community admin can only manage the membership.
  • Organizations can form a hierarchy while communities are independent of each other
  • Users must belong to an organization while joining a community is optional (not that this is actually configurable)

5. What is the use of control panel?

The Control Panel is a unified way to access all portal administration tools within Liferay. It provides access to:

6. DWR

DWR is an easy to use and powerful open source AJAX library. Get more details here.

7. WSRP

WSRP specification is about going much further and allow portals to display remote portlets inside their pages, as if locallly deployed, without requiring any additional programming by the developers. So you will be providing access to your business logic but also providing the user interface! In order to do so, WSRP define the following actors:
  • Producer: A Web Service that offers one or more portlets and is described using a WSDL document.
  • Consumer: The Web Service Client that gather all the components allowing for the presentation to the end user.
  • Portlets
  • End Users
          More details are  here.

8. Expando verses New table via service builder

Expando should only be used to expand upon existing entities, i.e. adding values to bind to a user for example. Basically when you need to add few attribute to existing entity. Service builder should be used when there are a lot of new attributes and the entity can logically be qualified as a separate entity.

9. How is Portlet different from Servlet?

Portlets should only generate their portion of an HTML page instead of the whole page like a Servlet does. URLs must only be created by using the Portlet API. Servlets had the flexibility to hand craft URLs while Portlets must delegate all URL creation to the Portal container. When creating a Portlet application, special attention needs to be given to the two lifecylce methods. The logic performed previously in the Servlet service (or doGet/doPost methods) must be broken up into the Portlet processAction and render methods. While many differences exist between Servlets and Portlets, it is possible to reuse some portions of Servlet web applications if they are well designed, separating out the processing/rendering logic and the header/footer HTML templates.

10. How to create Portlet?

Steps to create a liferay Portlet are here.

11. How to Customise portlet?

Steps and guidline to customize a Liferay portlet are here.


Comments

Popular posts from this blog

jQgrid reload with new data

OSS and BSS Systems

Rich Client based UI technologies- A Comparison of Thick Client UI tools