Thursday, May 16, 2013

How to create IPC Portlet in Liferay 6.1.1 ga2

The first version of the portlet specification, JSR-168/portlet1.0, did not include any support 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 IPC mechanisms, we can share the data from ACTION to VIEW phase and VIEW-VIEW Phase.

Public Render Parameter : IPC ( Inter Portlet Communication) :

In JSR 168, the render parameters set in processAction is only available in the render of the same portlet. 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.
By adding the following property in portlet-ext, we can enable portlets to share render states with other portlets that are on different pages: portlet.public.render.parameter.distribution=ALL_PORTLETS

Follow Steps to create IPC Portlet in Liferay 6.1.1 ga2

Step 1: Create new demoipc-portlet

Give first portlet name:sender

Step 2: Create second portlet in same project

Give portlet name:receiver

Step 3: In package com.test make two java class file

Sender.java
 
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 print default: 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"); } }
Receiver.java
 
package 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.EventResponse response) 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” -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 add both changes in same portlet.xml file
Portlet.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.xsd http://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> <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>

Step 5: A portlet can read public render parameter using following method

request.getPublicParameterMap()
Note: Public render parameters are merged with regular parameters so can also be
read using
request.getParameter(“id1”);

Step 6: A portlet can remove a public render parameter by invoking following methods

response.removePublicRenderParameter(“id1”)

Step 7: Make view.jsp for sender and receiver

 
 
Make view.jsp in html/sender/view.jsp View.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.jsp View.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 it

Installation of JBPM v6 Beta 2

JBoss Jbpm has launch new jbpm 6.0.0 beta2 version for Business Process Management.
It’s come with very new and useful components for BPM.
  1. The Eclipse BPMN2 Modeler
  2. The web-based designer

Configure Jbpm v6 Beta 2:

Step 1:

First of all, download full installer from this link http://sourceforge.net/projects/jbpm/files/jBPM%206/jbpm-6.0.0.Beta2/

Step 2:

Extract it into your local drive and set directory path in Command prompt and type following  Command. Ant  install.demo  
This will:
  • Download JBoss AS
  • Download Eclipse
  • Install the jBPM web tooling into JBoss AS
  • Install the jBPM and Drools Eclipse plugin
  • Install the BPMN2 Eclipse Modeler
This will take some time to install all these stuffs ,so wait for some time.You will get successful message.
Note:
You will get error message for  jbpm modeler because some jar file is not found on given link of build.xml .So after installation you will get older bpmn modeler. So I have covered how to install new bpmn modeler in next step 7.

Step 3:

Once the demo setup has finished,you can start this all components  by following command.
Ant  start.demo
This will:
  • Start the H2 database
  • Start the JBoss AS
  • Start Eclipse

Step 4:

After  successfully installing and starting all these components,
Install  the dashboard web application, which can be used to monitor your process instances.
To do so, run:
Ant install.dashboard.into.jboss

Step 5:

You can see by creating one bpmn process,there is old bpmn editor

Step 6:

So let’s install or update new Bpmn modeler

Step 7:

Click on help and then select install new software

Step 8:

Give any name and add following link

Step 9:

Now restart eclipse and you will get new bpmn2 modeler

Step 10:

Now let’s see one example
Make one jbpm project



Step 11:

You can see bpmn file and testing class

You can see bpmn modeler

Step 12:

Now let’s testing it

You can see output on console