Pages

Saturday, March 28, 2015

IPC through events Mechanism Liferay

Sender Portlet
1.Add below parameter in Portlet.xml

 <supported-publishing-event>
           <qname xmlns:x="http://liferay.com/events">x:ipc-parameters</qname>
  </supported-publishing-event>

2.Get the values from the sender jsps and  Set Events in your action class

@Override
public void processAction(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
// TODO Auto-generated method stub
QName qName = new QName("http://liferay.com/events", "ipc-parameters");
String name = ParamUtil.getString(actionRequest, "name","");
int age = ParamUtil.getInteger(actionRequest, "age");
double salary = ParamUtil.getDouble(actionRequest, "salary");
String parameters=name+','+String.valueOf(age)+','+String.valueOf(salary);

actionResponse.setEvent(qName, parameters.toString());

}

Receiver Portlet:
1.Add below parameter in Portlet.xml of receiver portlet
 <supported-processing-event>
            <qname xmlns:x="http://liferay.com/events">x:ipc-parameters</qname>
 </supported-processing-event>

and add below parameter after end of </portlet> and before end of </portlet-app>

<event-definition>
    <qname xmlns:x="http://liferay.com/events">x:ipc-parameters</qname>
</event-definition>  

2.Get the events values in process Events Method

@Override
@javax.portlet.ProcessEvent(qname = "{http://liferay.com/events}ipc-parameters")
public void processEvent(EventRequest request, EventResponse response)
throws PortletException, IOException {
Event event = request.getEvent();
String paramtervalues = (String) event.getValue();
response.setRenderParameter("parameters", paramtervalues);
}

No comments:

Post a Comment