掲示板

How to define IPC Events configuration using Liferay 7 modules framework

7年前 に Triveni B によって更新されました。

How to define IPC Events configuration using Liferay 7 modules framework

New Member 投稿: 21 参加年月日: 11/03/24 最新の投稿
I need to know configurations/annotations for IPC Events in Liferay 7

In earlier versions of liferay we have defined Event publishing configuration in Event Producer & Event Listener Portlet of portlet.xml file
Similar way how to achieve using Liferay 7 modular based framework.

Can anybody help me
thumbnail
7年前 に David H Nebinger によって更新されました。

RE: How to define IPC Events configuration using Liferay 7 modules framewor

Liferay Legend 投稿: 14917 参加年月日: 06/09/02 最新の投稿
On your portlet annotation you'll add javax.portlet.supported-processing-event and javax.portlet.supported-publishing-event properties to add your event definitions.








Come meet me at the LSNA!
7年前 に Triveni B によって更新されました。

RE: How to define IPC Events configuration using Liferay 7 modules framewor

New Member 投稿: 21 参加年月日: 11/03/24 最新の投稿
Thanks for your response.
Can you elaborate bit more, I am bit confusing how to use below kind of code in portlet annotations
<portlet-app>
-----
<supported-publishing-event xmlns:event="http://www.liferay.com">
<qname>event:StudentObj</qname>
</supported-publishing-event>
</portlet>
<event-definition xmlns:event="http://www.liferay.com">
<qname>event:StudentObj</qname>
<value-type>MapObject</value-type>
</event-definition>
</portlet-app>

I have used if properties coming from portlet.xml prefixed with javax.portlet &
if properties coming from liferay-portlet.xml prefixed with com.liferay.portlet
thumbnail
7年前 に David H Nebinger によって更新されました。

RE: How to define IPC Events configuration using Liferay 7 modules framewor

Liferay Legend 投稿: 14917 参加年月日: 06/09/02 最新の投稿
Sorry, I only know the property keys and haven't been able to find an example yet. The blade samples may have something though...

I basically don't use the events, never really found a good use case for them since they cause full page refreshes and what not.







Come meet me at the LSNA!
7年前 に Alexander Seitz によって更新されました。

RE: How to define IPC Events configuration using Liferay 7 modules framewor

New Member 投稿: 6 参加年月日: 16/10/19 最新の投稿
Hi Triveni B,

I had the same Problem and spend hours of searching how to achieve Inter Portlet Communication (IPC) with Liferay 7 and OSGi.
emoticon
Sadly there currently isn't much help for IPC in the offical liferay documentation. This should be fixed. emoticon The only hint I found is, that in liferay 7 with osgi there is no "portlet.xml" configuration file anymore. Instead with OSGi and Liferay 7 the configuration properties from the portlet.xml are now moved into the @Component annotation (at the header of the class) of each Portlet:

Example:

@Component(
	immediate = true,
        property = {
                // Configuration properties from former portlet.xml are used here:
		"com.liferay.portlet.display-category=category.sample",
		"com.liferay.portlet.instanceable=true",
		"javax.portlet.display-name=OsgiTest Portlet",
		"javax.portlet.init-param.template-path=/",
		"javax.portlet.init-param.view-template=/view.jsp",
		"javax.portlet.resource-bundle=content.Language",
		"javax.portlet.security-role-ref=power-user,user"
	},
	service = Portlet.class
)
public class OsgiMVCPortlet extends MVCPortlet { ...}


There is a JSR-168 & JSR-286 Descriptor Mapping Page in the official documentation, which tells us, that we have to use:

for the IPC-Sender Portlet:
javax.portlet.supported-processing-event=<String>;<QName>
and for IPC-Receiver Portlet:
javax.portlet.supported-publishing-event=<String>;<QName>

My Problem was: How do I pass QName and how is the Syntax for these two properties? I tried a lot with passing new Qname(...)-Instance etc...and I failed every time. After a couple of hours, and getting some encouraging words from jardineworks in the IRC Channel, I finally found the solution by having a look into the official Liferay Source Code from github. Ohh I'm so glad that Liferay is Open Source ;-)
Have a look at Line 845 from PortletTracker-Class, where publishing-events and processing-events are handled:

https://github.com/liferay/com-liferay-portal-osgi-web/blob/master/portal-osgi-web-portlet-tracker/src/main/java/com/liferay/portal/osgi/web/portlet/tracker/internal/PortletTracker.java

You'll see that passing an QName-Instance is not the right way. Instead we have to pass two Strings. The first String is the name for the event you want to fire, the second one is optional and defines the namespace in which the portlets are communicating with each other:
for example:
"javax.portlet.supported-publishing-event='eventName';'http://my-unique-namespace.com'"


Giving you full working Example, that means we have to configure the following properties for an IPC-Event with Portlets in Liferay 7 and Osgi:

IPC-Event: SENDER-PORTLET
In OsgiSenderMVCPortlet.cass

@Component(
	immediate = true,
	property = {
		"com.liferay.portlet.display-category=category.sample",
		"com.liferay.portlet.instanceable=true",
		"com.liferay.portlet.requires-namespaced-parameters=false",
		"com.liferay.portlet.ajaxable=true",
		"javax.portlet.display-name=IPC-Sender Porlet",
		"javax.portlet.init-param.template-path=/",
		"javax.portlet.init-param.view-template=/view.jsp",		
		"javax.portlet.resource-bundle=content.Language",
		// Here we define an portlet.xml property, for sending an Event with the name "selectedReport" and a custom namespace
		//"javax.portlet.supported-publishing-event=<string>;<qname>",
		"javax.portlet.supported-publishing-event=selectedReport;https://my-liferay-namespace.com/events",
		"javax.portlet.security-role-ref=power-user,user"
	},
	service = Portlet.class
)
public class OsgiSenderMVCPortletextends MVCPortlet {
...
  // this method is beeing called by an <portlet:actionurl> from the view.jsp
  public void selectReportAction(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException {
      String exampleData = actionRequest.getParameter("inputParam");
      System.out.println("submitted value is " +exampleData);
      QName qName = new QName("https://my-liferay-namespace.com/events","selectedReport");
      actionResponse.setEvent(qName, exampleData);
   }
...
}
</portlet:actionurl></qname></string>



IPC-Event: RECEIVER-PORTLET
In OsgiReceiverMVCPortlet.cass

@Component(
	immediate = true,
	property = {
		"com.liferay.portlet.display-category=category.sample",
		"com.liferay.portlet.instanceable=true",
		"com.liferay.portlet.requires-namespaced-parameters=false",
		"javax.portlet.display-name=IPC-Receiver Portlet",		
		"javax.portlet.init-param.template-path=/",
		"javax.portlet.init-param.view-template=/view.jsp",
		"javax.portlet.resource-bundle=content.Language",
		// Here we define an portlet.xml property, for receiving an Event with the name "selectedReport" for a custom namespace
		//"javax.portlet.supported-processing-event=<string>;<qname>"
		"javax.portlet.supported-processing-event=selectedReport;https://my-liferay-namespace.com/events",
		"javax.portlet.security-role-ref=power-user,user"
	},
	service = Portlet.class
)
public class OsgiReceiverMVCPortlet extends MVCPortlet{
...
@Override
   public void processEvent(EventRequest request, EventResponse response) throws PortletException, IOException {      
      Event event = request.getEvent();
      if(event.getName().equals("selectedReport")){
         System.out.println("selectedReport Event found!");
         String eventValue = (String) event.getValue();
         System.out.println("show me that value from the IPC-Event: " + eventValue);
      }
      super.processEvent(request, response);
   }
...
}
</qname></string>


My example uses a simple String as the event data. But you can use whatever data object you'd like to sent with the event.
I left out the structure of the *.jsp view file is, cause there are some good examples out there. The good tutorial for IPC which I used is
http://roufid.com/liferay-portlet-communication-using-event/

*happy coding*
emoticon


@Developers/Liferay-Documentation-Authors:
It would be rly nice, if you could provide a learning path for liferay 7 with fully working examples, covering the basics from liferay 7 with osgi.
For example, developing a basic product page. Could even be a liferay developer session on youtube.
Basics steps to get newbies like me going with liferay and makes it easier to start with. IMHO the official documentation for liferay 7 is a pain in the...ahm I mean it's rly hard to read and there are lot of topic jumps. One basic product page example with 2-4 simple portlets and services for each technology branch (JSP, JSF, JS/Angular/REST) would be awesome.
7年前 に A. Rock によって更新されました。

RE: How to define IPC Events configuration using Liferay 7 modules framewor

New Member 投稿: 6 参加年月日: 16/10/19 最新の投稿
In addition, I would like to mention that it is way easier if you do Client Side IPC instead of IPC-Events.

You need the have the communcating Portlets on the same page, then you only need to add two little javascript snippets in the jsp/jsf view page:

Client-Side IPC: EVENT-SENDER
in view.jsp:

/**
 * Send IPC-Event over Liferay Ajax
 **/
 function _fireIPCEvent(selectedLabel){         
    Liferay.fire('selectReportEvent',{
       param1: selectedLabel                      
   });         
 }



Client Side IPC: EVENT-RECEIVER
in view.jsp:

/**
 * Receive IPC-Event from a Liferay Ajax Call
 **/
Liferay.on('selectReportEvent',function(event) {
   var parameterValue1 = event.param1;
   console.log("received value is "+parameterValue1);  
});