简体   繁体   中英

Event Based IPC(Inter portlet communication using Event)

I'm new in Liferay. I have problem with communication between two portlets that are in different liferay plugin project. To understand I'm using a sample code that I have find on the web. When I push on the button appears this error:

java.lang.NoSuchMethodException: com.liferay.util.bridges.mvc.MVCPortlet.processFood(javax.portlet.ActionRequest, javax.portlet.ActionResponse) at java.lang.Class.getMethod(Unknown Source).

This is the code:

view.jsp (Sender)

    <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<portlet:actionURL name="processFood" var="actionUrl"></portlet:actionURL>

<form action="<%=actionUrl %>" method="POST">
<h3><input type="radio" name="foodType" value="veg">Vegetarian<br><br></h3>
<h3><input type="radio" name="foodType" value="non-veg">Non - Vegetarian<br><br></h3>
<input type="submit" name="Submit" value="Submit">
</form>

view.jsp (Receiver)

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<portlet:defineObjects />

<c:set var="food" value="${foodType}"/>

<c:choose>
    <c:when test="${food == 'veg'}">
       <h3><font color="green"> You are Vegetarian. You Can Enjoy Dosa</font></h3>
    </c:when>
    <c:when test="${food == 'non-veg'}">
     <h3> <font color="red">You are Non - Vegetarian. You can enjoy Chicken.</font></h3>
    </c:when>
    <c:otherwise>
     <h3>Please Select Food Type</h3> 
    </c:otherwise>
</c:choose>

Sender.java

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.ProcessAction;
import javax.xml.namespace.QName;

import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;

public class Sender extends MVCPortlet {

    @ProcessAction(name="processFood")
    public void processFood(ActionRequest request, ActionResponse response) throws PortletException, IOException {
        String foodType = ParamUtil.getString(request, "foodType" ,"default");

        if(!foodType.equalsIgnoreCase("default"))
        {
            //We fetch Qname from portlet.xml and set value in it
            QName foodEvent = new QName("http://aditya/events", "foodType");
            response.setEvent(foodEvent, foodType);
        }
    }
}

Receiver.java

import javax.portlet.Event;
import javax.portlet.EventRequest;
import javax.portlet.EventResponse;
import javax.portlet.ProcessEvent;
import com.liferay.util.bridges.mvc.MVCPortlet;

public class Receiver extends MVCPortlet {

    @ProcessEvent(qname = "{http://aditya/events}foodType")
    public void receiveFoodType(EventRequest request, EventResponse response) {
        Event event = request.getEvent();
        String foodType  = (String) event.getValue();  
        request.setAttribute("foodType", foodType);    
    }
}

Thanks

I think your problem is that you put in your portlet.xml file in the Receiver portlet the tag <supported-publishing-event> but you have to use the tag <supported-processing-event> .

You can see more details in this url: https://www.liferay.com/es/community/wiki/-/wiki/Main/Portlet+to+Portlet+Communication

Hope this helps. Regards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM