我是Liferay的新人。我在不同的liferay插件项目中的两个portlet之间的通信有问题。要了解我使用的是我在网上找到的示例代码。当我按下按钮时出现此错误:
java.lang.NoSuchMethodException: com.liferay.util.bridges.mvc.MVCPortlet.processFood(javax.portlet.ActionRequest, javax.portlet.ActionResponse) at java.lang.Class.getMethod(Unknown Source).
这是代码:
view.jsp(发件人)
<%@ 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);
}
}
由于
答案 0 :(得分:0)
我认为您的问题是您在标记为<supported-publishing-event>
的Receiver portlet中放入了portlet.xml文件,但您必须使用标记<supported-processing-event>
。
您可以在此网址中查看更多详细信息:https://www.liferay.com/es/community/wiki/-/wiki/Main/Portlet+to+Portlet+Communication
希望这会有所帮助。问候。