留言板

IPC Event Not Working for CustomBean Object - Spring MVC Portlet

thumbnail
Subhasis Roy,修改在9 年前。

IPC Event Not Working for CustomBean Object - Spring MVC Portlet

Expert 帖子: 275 加入日期: 12-1-20 最近的帖子
Hi,

I have 2 portlets. I am trying to pass one custom java bean object(EmployeeBean.java) from one portlet to another using IPC event.

I have added the following property in portal-ext.properties file:

portlet.event.distribution=layout-set


Then added the following in the portlet.xml for sender portlet.

portlet.xml entry:
<supported-publishing-event xmlns:x="http://liferay.com">
        <qname>x:empinfo</qname>
</supported-publishing-event>

<event-definition xmlns:x="http://liferay.com">
        <qname>x:empinfo</qname>
        <value-type>com.test.EmployeeBean</value-type>
</event-definition>


And added the object in the Action Response in processAction method of the Sender portlet.

javax.xml.namespace.QName qName = new QName("http://liferay.com", "empinfo", "x");
response.setEvent(qName, empBeanObj);


Receiver portlet code:

@javax.portlet.ProcessEvent(qname = "{http://liferay.com}empinfo")
    public void handleProcessempinfoEvent(javax.portlet.EventRequest request, javax.portlet.EventResponse response) 
                throws javax.portlet.PortletException, java.io.IOException {
        
		logger.info("Listener portlet-class is getting called.....");
        javax.portlet.Event event = request.getEvent();
        logger.info("Event value is: "+event);
        EmployeeBean empBeanObjt = (EmployeeBean) event.getValue();
}


But I am not able to fetch the data in the Receiver portlet. This method is not getting called.
Can any one please help me whether I am missing something while calling the event
thumbnail
Ajeykumar HB,修改在9 年前。

RE: IPC using event not working for custom bean object

Junior Member 帖子: 72 加入日期: 12-3-13 最近的帖子
Hi Subhasis,

I thought your added the event processing entry in your receiver portlet, portlet.xml also?
if it is not please add it.

<supported-processing-event xmlns:x='http://liferay.com'>
<qname>x:empinfo</qname>
</supported-processing-event>

<event-definition xmlns:x='http://liferay.com'>
<qname>x:empinfo</qname>
<value-type>com.test.EmployeeBean</value-type>
</event-definition>

and also

use portlet.event.distribution= in your portal-ext.properties file,if portlet or in two different page or in two different war file.
thumbnail
Subhasis Roy,修改在9 年前。

RE: IPC using event not working for custom bean object

Expert 帖子: 275 加入日期: 12-1-20 最近的帖子
Yes, I did both what you have mentioned.

# portal-ext entry:
portlet.event.distribution=layout-set


#Receiver XML entry:

<supported-processing-event xmlns:x="http://liferay.com">
            <qname>x:empinfo</qname>
</supported-processing-event>


But somehow the Receiver portlet method handleProcessempinfoEvent not getting called. Should I need to make any more changes.
thumbnail
Ketan Savaliya,修改在9 年前。

RE: IPC using event not working for custom bean object

Regular Member 帖子: 117 加入日期: 11-3-3 最近的帖子
Hi Subhasis,

I think you can't set custom bean into IPC even.
Just try with String and check it's work or not? if yes then convert your parameter into string and then set into IPC query.
thumbnail
Subhasis Roy,修改在9 年前。

RE: IPC using event not working for custom bean object

Expert 帖子: 275 加入日期: 12-1-20 最近的帖子
I am getting the following error in the processAction of the sender

Error Log:

[5/20/14 13:08:54:193 IST] 00000304 SystemOut O 13:08:54,193 ERROR [WebContainer : 7][PortletServlet:115] org.springframework.web.portlet.NoHandlerFoundException: No matching handler method found for portlet request: mode 'view', phase 'EVENT_PHASE', parameters map[[empty]]
org.springframework.web.portlet.NoHandlerFoundException: No matching handler method found for portlet request: mode 'view', phase 'EVENT_PHASE', parameters map[[empty]]
at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter$PortletHandlerMethodResolver.resolveHandlerMethod(AnnotationMethodHandlerAdapter.java:510)
at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:359)
at org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter.doHandle(AnnotationMethodHandlerAdapter.java:349)



I am getting the above error for the following in line in processAction. Its not able to get the setEvent in the ActionResponse object

response.setEvent(qName, empBeanObj);

@ActionMapping(value = "setSearchCriteria")
public void setSearchCriteria(final Model model,@Valid @ModelAttribute("merchantOverview") final MerchantOverviewCommand command,
 final BindingResult result, final PortletSession session, ActionRequest request, ActionResponse response) {

        EmployeeBean empBeanObj = fetchEmpData(empNumber);

        javax.xml.namespace.QName qName = new QName("http://liferay.com", "empinfo", "x");
          response.setEvent(qName, empBeanObj);
}
thumbnail
Subhasis Roy,修改在9 年前。

RE: IPC using event not working for custom bean object

Expert 帖子: 275 加入日期: 12-1-20 最近的帖子
Hi,

I got the issue with my code. You are correct. We can not pass the custom bean object. This is a issue with Liferay Portal.

It got fixed in Liferay 6.2.0 CE M4 version. For any prior version to this one, IPC Event only works for String type Refer URL below -

Portlet 2.0 Event: request.getEvent().getValue() returns null, if value !instanceof String

Nice Ref for IPC - Event
thumbnail
Ketan Savaliya,修改在9 年前。

RE: IPC using event not working for custom bean object

Regular Member 帖子: 117 加入日期: 11-3-3 最近的帖子
Hi Subhasis Roy,

Thank you very much for update me and community as well.
thumbnail
Subhasis Roy,修改在9 年前。

[Solved] IPC Event Not Working for CustomBean Object - Spring MVC Portlet

Expert 帖子: 275 加入日期: 12-1-20 最近的帖子
Hi Ketan,

I am able to successfully pass the custom bean object using IPC Event. I am using Liferay version 6.1.0.

#Publisher portlet.xml entry:

<portlet>
         <portlet-name>SenderPortlet</portlet-name>
		<display-name>Sender Portlet</display-name>
	    <display-name xml:lang="en">Sender Portlet</display-name>
		<portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>		
		<init-param>
			<name>contextConfigLocation</name>	
			<value>classpath:context/portlet/senderPortlet.xml</value>
		</init-param>
		
		<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>view</portlet-mode>
		</supports>	
		<supported-locale>en</supported-locale>
		<supported-locale>es</supported-locale>
		<resource-bundle>messages.senderPortlet</resource-bundle>
  <supported-publishing-event>
            <qname xmlns:x="http://liferay.com/events">x:empDetailBean</qname>
   </supported-publishing-event>
</portlet>

<event-definition>
       <qname xmlns:x="http://liferay.com/events">x:empDetailBean</qname> 
       <value-type>com.test.personal.EmployeeBean</value-type>
</event-definition>


# Publisher Controller Code

@ActionMapping(value = "setSearchCriteria")
public void setSearchCriteria(final Model model, ActionRequest request, ActionResponse response) {

//..other codes
EmployeeBean empBeanObj = fetchempDetails(empID);
//...other codes
javax.xml.namespace.QName qName = new QName("http://liferay.com/events", "empDetailBean", "x");
response.setEvent(qName, empBeanObj);
}


# Receiver/Processor portlet.xml entry:


<portlet>
		<portlet-name>ReceiverPortlet</portlet-name>
		<display-name>Receiver Portlet</display-name>
	    <display-name xml:lang="en">Receiver Portlet</display-name>
		<portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>		
		<init-param>
			<name>contextConfigLocation</name>	
			<value>classpath:context/portlet/receiverPortlet.xml</value>
		</init-param>
		
		<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>view</portlet-mode>
		</supports>	
		<supported-locale>en</supported-locale>
		<supported-locale>es</supported-locale>
		<resource-bundle>messages.receiverPortlet</resource-bundle>
      <supported-processing-event>
          <qname xmlns:x="http://liferay.com/events">x:empDetailBean</qname>
     </supported-processing-event>
</portlet>
<event-definition>
       <qname xmlns:x="http://liferay.com/events">x:empDetailBean</qname> 
       <value-type>com.test.personal.EmployeeBean</value-type>
</event-definition>


# Receiver/Processor Controller Code:

import javax.portlet.EventPortlet;
import javax.portlet.EventRequest;
import javax.portlet.EventResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Controller
@RequestMapping("VIEW")
public class EventReceiverController implements EventPortlet{

private static final Logger logger = LoggerFactory.getLogger(EventReceiverController .class);

@EventMapping
public void processEvent(EventRequest request, EventResponse response) throws PortletException, IOException {
	javax.portlet.Event event = request.getEvent();
        EmployeeBean empBeanObj = (EmployeeBean) event.getValue();
        logger.info("emp name: "+empBeanObj.getEmployeeName());
        response.setRenderParameter("empDetailObject", empBeanObj.toString());
        response.setRenderParameter("empFirstName", empBeanObj.getEmpFirstName());
        //request.getPortletSession().setAttribute("empDetailObject", empBeanObj);
}


You need to implement EventPortlet Interface in your Event Receiver Portlet Controller class.

## Note:
The @EventMapping will only applicable to the Single event per portlet.
For multiple events we need to use @EventMapping(value ="{http://liferay.com/events}empDetailBean}" . This multiple event I haven't tested. But Single one is tested and working successfully

In the above example my Sender and Receiver portlets are in the same page. But if the Sender and Receiver portlets are in different page, then we need add the following entry in the portal-ext.properties file.

## portal-ext.properties entry

portlet.event.distribution=layout-set


Some nice References:
Reference : Liferay IPC
Reference : Spring Portlet IPC
Reference : Spring IPC
IPC - Liferay Solutions
Client Side IPC