嗨,我嘗試從liferay文檔中做portlet。但我的java類別不工作。來自liferay文檔的portlet
MyGreetingPortlet
package com.liferay.samples;
import java.io.IOException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletPreferences;
import com.liferay.util.bridges.mvc.MVCPortlet;
public class MyGreetingPortlet extends MVCPortlet { @Override
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException {
PortletPreferences prefs = actionRequest.getPreferences();
String greeting = actionRequest.getParameter("greeting");
if (greeting != null) {
prefs.setValue("greeting", greeting);
prefs.store();
}
super.processAction(actionRequest, actionResponse);
}
}
view.jsp的
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ page import="javax.portlet.PortletPreferences" %>
<portlet:defineObjects />
<% PortletPreferences prefs = renderRequest.getPreferences();
String greeting = (String)prefs.getValue("greeting", "Hello! Welcome to our portal."); %>
<p><%= greeting %></p>
<portlet:renderURL var="editGreetingURL"> <portlet:param name="jspPage" value="/edit.jsp" />
</portlet:renderURL>
<p><a href="<%= editGreetingURL %>">Edit greeting</a></p>
edit.jsp文件
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%@ page import="com.liferay.portal.kernel.util.Validator" %>
<%@ page import="javax.portlet.PortletPreferences" %>
<portlet:defineObjects />
<% PortletPreferences prefs = renderRequest.getPreferences();
String greeting = (String)prefs.getValue("greeting", "Hello! Welcome to our portal."); %>
<portlet:actionURL var="editGreetingURL"> <portlet:param name="jspPage" value="/edit.jsp" />
</portlet:actionURL>
<form action="<%= editGreetingURL %>" method="post">
<label><input type="text"><%= greeting %></label>
<input type="submit" name="submit" value="Submit">
</form>
<portlet:renderURL var="viewGreetingURL">
<portlet:param name="jspPage" value="/view.jsp" />
</portlet:renderURL>
<p><a href="<%= viewGreetingURL %>">← Back</a></p>
後部署JSP運行正常,但是當我點擊提交按鈕沒有heppens。我在這個例子中只改變了一件事:刪除aui標籤,但不認爲chage的東西,我已經嘗試了一些不同的例子,沒有人使用java類。哦,我使用MVC portlet。
我將portlet-class更改爲portlet.xml中的portlet。 –
日誌中的任何錯誤。你怎麼確定點擊提交不會調用MyGreeting portlet的processAction。您可以在portlet類的processAction方法中放入一些日誌語句或System.out.println –
我沒有看到任何erorrs。它來自這裏的例子http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/understanding-the-two-phases-of-portlet-executi-4 –