Total Pageviews

Saturday, August 13, 2016

Liferay: Client Side IPC via Cookies

I’m starting to write here again after long time. I was keeping busy while working on ReactJS and it’s integration with Liferay. However, I’m here continuing from where I left and will start about ReactJs and its integration with Liferay soon. 

In the previous two posts we’ve seen IPC via Public Render Parameter and Server Side Events. Today I’ll write about Client Side IPC at using Cookies. As IPC via Public Render Parameters and Server Side Events, this concept was also introduced in JSR 286.

Important point to note about Client Side IPC via Cookies is that we cannot have information stored/shared more than 4096 bytes in size, as this is the maximum size of a cookie allowed by browsers and maximum number of cookies allowed, varies browser to browser; which is, for example, 20 in case of IE and 600 in case of Safari Mobile. (You can read details here)

The scenario we’ll see here in snippet will be: creating the cookie in Portlet 1 and reading the same in portlet 2. I’m keeping name of the cookie ‘sampleIPCCookie’ for example.
Setting/Getting the cookie can be done by either of the method - server side (Java/JSP etc.) or client side (Javascript/JQuery etc.). Here I am writing example using of Javascript.

Let’s go and see the snippets.
Portlet 1: Setting the cookie 


Portlet 2: Fetching the cookie value in another portlet. 
Client Side IPC via cookies is not a best practice of IPC and should be considered as the last option for implementing IPC. If it is very necessary to implement IPC at client side, one should first consider Client Side Events (which we’ll see in the next post) before considering this mechanism.

That’s all for today. Thanks for reading and have a nice day.

Sunday, May 31, 2015

Liferay: IPC via Server Side Events

IPC (Inter Portlet Communication) in Liferay can be implemented in different ways and  I've already written an article on Public render parameter mechanism. In this article, we'll see Event based IPC. As Public Render Parameters, this concept was also introduced in JSR 286.

As per IPC using Events, portlet can publish/send and process/receive the event. This mechanism works flawlessly with inter and intra WARs.

1. Event deceleration in Event Publisher Portlet's portlet.xml
Full portlet.xml will look like as follows:

2. Event definition in Event Receiver Portlet's portlet.xml
Full portlet.xml will look like as follows:
3. Event Publishing Portlet's Controller Class

Invoking Publish Event method

4. Event Processing Portlet's Controller Class and fethching parameter's value
Note: 'QName' is a nothing but a qualified name of the parameter. Usage of QName minimizes chances of having two identical events.

Saturday, May 30, 2015

Liferay: IPC using Public Render Parameters

IPC (Inter Portlet Communication) in Liferay can be implemented in different ways and  we'll see one among the possibilities, i.e. Public Render Parameter. This concept was introduced in JSR 286.

The central idea of this concept is to share a normal parameter across all deployed portlets despite of the fact that they lie in same WAR or in different.

1. In portlet.xml in the end of </portlet> tag we have to define the name of parameter

2. In portlet.xml in the end of <portlet-app> tag we have to define the identifier with the name of parameter

Full portlet.xml file will look like as follows:

Setting Parameter:

Reading Parameter:

Note: If render parameters need to be shared among two different WARs, and you have to set parameter in portlet 1 and read in portlet 2, For achieving this, we have to add definition of render parameter in the portlet.xml file of both the WARs.