Create IPC Portlet in Liferay 6.1.1 ga2

776 views
668 views

Published on

create IPC portlet in Liferay 6.1.1 ga2. Liferay development is not at all an simpley task as it requires a expetise with vast experience. Attune Infocom is one of the fastest growing Liferay development firms, which has an extremely talented pool of liferay developers who can develop custom liferay portals for you.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
776
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Create IPC Portlet in Liferay 6.1.1 ga2

  1. 1. Create IPC Portlet in Liferay 6.1.1 ga2The first version of the portlet specification, JSR-168/portlet1.0, did not include anysupport for Inter Portlet Communication. The second version, JSR-286/ portlet2.0,which is supported for IPC Mechanism.IPC is made easy with JSR-286 to share the data between two portlets. Using IPCmechanisms, we can share the data from ACTION to VIEW phase and VIEW-VIEWPhase.Public Render Parameter: IPC (Inter Portlet Communication):In JSR 168, the render parameters set in processAction is only available in the render of thesame portlet. With the Public Render Parameters feature, the render parameters set in theprocessAction of one portlet will be available in render of other portlets also.By adding the following property in portlet-ext, we can enable portlets to share renderstates with other portlets that are on different pages:portlet.public.render.parameter.distribution=ALL_PORTLETSFollow Steps to create IPC Portlet in Liferay 6.1.1 ga2Step 1: Create new demoipc-portletGive first portlet name:senderStep 2: Create second portlet in same projectGive portlet name:receiverStep 3: In package com.test make two java class fileSender.java
  2. 2. package com.test;import java.io.IOException;import java.util.Random;import javax.portlet.ActionRequest;import javax.portlet.ActionResponse;import javax.portlet.PortletException;import javax.portlet.PortletRequestDispatcher;import javax.portlet.ProcessAction;import javax.portlet.RenderRequest;import javax.portlet.RenderResponse;import javax.xml.namespace.QName;import com.liferay.portal.kernel.log.Log;import com.liferay.portal.kernel.log.LogFactoryUtil;import com.liferay.util.bridges.mvc.MVCPortlet;/*** Portlet implementation class sender*/public class sender extends MVCPortlet {@ProcessAction(name="pitchBall")public void pitchBall(ActionRequest request, ActionResponse response) {String pitchType = null;System.out.println("pitch call");// Send an Event that the ball has been pitched.Random random = new Random(System.currentTimeMillis());int pitch = random.nextInt(3) + 1;switch (pitch) {case 1:pitchType = "Fast Ball";break;case 2:pitchType = "Curve Ball";break;case 3:pitchType = "Slider";break;// should never printdefault:pitchType = "Screw Ball";}pitchType=pitchType+"Hai You have received Event Data sent from Sender Portlet";javax.xml.namespace.QName qName =new QName("http://liferay.com", "ipc.pitch", "x");response.setEvent(qName,pitchType);System.out.println("call here");
  3. 3. }}Receiver.javapackage com.test;import javax.portlet.Event;import javax.portlet.EventRequest;import javax.portlet.EventResponse;import javax.portlet.ProcessEvent;import com.liferay.util.bridges.mvc.MVCPortlet;/*** Portlet implementation class receiver*/public class receiver extends MVCPortlet {@javax.portlet.ProcessEvent(qname = "{http://liferay.com}ipc.pitch")public void handleProcessempinfoEvent(javax.portlet.EventRequest request, javax.portlet.EventResponseresponse)throws javax.portlet.PortletException, java.io.IOException {javax.portlet.Event event = request.getEvent();String value = (String) event.getValue();System.out.print("value in process event>>>>>>>>>" + value);response.setRenderParameter("ipc.pitch", value);}}Step 4: Edit the portlet.xml-Add below attribute in “Sender-Portlet”-Before closing of </portlet><supported-processing-event xmlns:x=http://liferay.com><qname>x:ipc.pitch</qname></supported-processing-event></portlet><event-definition xmlns:x=http://liferay.com><qname>x:ipc.pitch</qname><value-type>java.lang.String</value-type></event-definition></portlet-app>Note: We can declare a list of public paramters for a portlet application.-Add below attribute in “recevier-Portlet”
  4. 4. -Before closing of </portlet><supported-processing-event xmlns:x=http://liferay.com><qname>x:ipc.pitch</qname></supported-processing-event></portlet><event-definition xmlns:x=http://liferay.com><qname>x:ipc.pitch</qname><value-type>java.lang.String</value-type></event-definition></portlet-app>In my example I have created both portlet in same project so here I have addboth changes in same portlet.xml filePortlet.xml<?xml version="1.0"?><portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsdhttp://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0"><portlet><portlet-name>sender</portlet-name><display-name>sender</display-name><portlet-class>com.test.sender</portlet-class><init-param><name>view-jsp</name><value>/html/sender/view.jsp</value></init-param><expiration-cache>0</expiration-cache><supports><mime-type>text/html</mime-type><portlet-mode>view</portlet-mode></supports><portlet-info><title>sender</title><short-title>sender</short-title><keywords></keywords></portlet-info><security-role-ref><role-name>administrator</role-name></security-role-ref><security-role-ref><role-name>guest</role-name></security-role-ref><security-role-ref>
  5. 5. <role-name>power-user</role-name></security-role-ref><security-role-ref><role-name>user</role-name></security-role-ref><supported-processing-event xmlns:x=http://liferay.com><qname>x:ipc.pitch</qname></supported-processing-event></portlet><portlet><portlet-name>receiver</portlet-name><display-name>receiver</display-name><portlet-class>com.test.receiver</portlet-class><init-param><name>view-jsp</name><value>/html/receiver/view.jsp</value></init-param><expiration-cache>0</expiration-cache><supports><mime-type>text/html</mime-type><portlet-mode>view</portlet-mode></supports><portlet-info><title>receiver</title><short-title>receiver</short-title><keywords></keywords></portlet-info><security-role-ref><role-name>administrator</role-name></security-role-ref><security-role-ref><role-name>guest</role-name></security-role-ref><security-role-ref><role-name>power-user</role-name></security-role-ref><security-role-ref><role-name>user</role-name></security-role-ref><supported-processing-event xmlns:x=http://liferay.com><qname>x:ipc.pitch</qname></supported-processing-event></portlet><event-definition xmlns:x=http://liferay.com><qname>x:ipc.pitch</qname><value-type>java.lang.String</value-type></event-definition></portlet-app>
  6. 6. Step 5: A portlet can read public render parameter using followingmethodrequest.getPublicParameterMap()Note: Public render parameters are merged with regular parameters so can also beread usingrequest.getParameter(“id1”);Step 6: A portlet can remove a public render parameter by invokingfollowing methodsresponse.removePublicRenderParameter(“id1”)Step 7: Make view.jsp for sender and receiverMake view.jsp in html/sender/view.jspView.jsp<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %><portlet:defineObjects />vbjhbnj<p>Click the link below to pitch the ball. </p><a href="<portlet:actionURL name="pitchBall"></portlet:actionURL>">Pitch!</a>Make view.jsp in html/recevier/view.jspView.jsp<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %><portlet:defineObjects /><%String pitch = (String)renderRequest.getParameter("ipc.pitch");%><p>And the pitch is....</p><p><% if (pitch!=null) { %><%=pitch %>!<% } else { %>... waiting for pitch.<% } %>Step 8: now deploy it and check itLiferay development is not at all an simpley task as it requires a expetise with vastexperience. Attune Infocom is one of the fastest growing Liferay development firms,which has an extremely talented pool of liferay developers who can develop customliferay portals for you. Attuene Infocom offer outsource Liferay Portal developmentsolution at worldwide.

×