Wednesday, October 14, 2015

Inter Portlet Communication (IPC) using Public Render Parameter in Liferay

We already know that render Parameter set in processAction is available to render method of same portlet. But if we set render parameter in one portlet and want to get in another portlet . In this case we use Public Render Parameter so that parameter set in one portlet can be available to another Portlet.This feature is known as Inter Portlet Communication(IPC)  using Public Render Parameter.

We take a simple scenario where user can select food type from one portlet and second portlet shows food items on the basis of first portlet. This is a Sender, Receiver kind of scenario.Here we create two project and each project contain one portlet.

So lets start this step by step:-

For Sender

Step 1:-Create Liferay Project and Portlet
Inside eclipse IDE Click on File->New->Liferay plugin project and give the project name as prp_sender and click finish. After that Right Click on your project ie prp_sender and click on New than click on Liferay Portlet. Provide class and package name and select MVCPortlet and click finish.

Note:-You can check the snapshots in my  blog on Portlet Configuration Page in Liferay.

Step 2:-Change portlet.xml
Open portlet.xml and enter supported public render parameter tag and public render parameter tags :-

Here we set two things:-

1)Tell Portlet that we are using public render parameter as:-

2)Use Qualified name(qname) so that parameter name-spaced properly to resolve conflicts.
                <qname xmlns:x="http://aditya/public">

Step 3:-Change view.jsp
Open view.jsp and paste this content:-

Note:- We are not using namespaces, so set required namespace parameter property is false in liferay-portlet.xml.

Step 4:-Change the Controller
Open your Controller and paste this:-

Here we just fetch the value from jsp and set in render Parameter.

For Receiver

Step 1:-Create Liferay Project and Portlet
Similarly as in Sender Create project with name prp-receiver and create a portlet in it.

Step 2:-Change portlet.xml
Similarly as in Sender change  portlet.xml of Receiver as:-

Step 3:-Change the Controller
Open your Controller and paste this:-

Here we get the value from render parameter and set in attribute so that we can use this on jsp.

Step 4:-Change the jsp
Open view.jsp and paste this :-

Here we get the value that is set in Controller and on the basis of condition show different messages.

Note:- We are using jstl tage here so provide entry in file as:-

For Output

Now deploy both sender and receiver portlet and add to same page .

Now Select Vegetarian and click submit

Select Non-Vegetarian and click submit

Note:-Now if you want to add the portlet on different pages .You need to provide a entry in as:-


Hope this will Help....

You can Download Source code from  IPC using Public Render Parameter.

Related Post:-

No comments:

Post a Comment

Total Pageviews

Number Of Unique Visitor

Free counters!