Liferay ActionRequest
Liferay ActionRequest
java 檔
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.portal.kernel.servlet.SessionMessages;
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();
}
SessionMessages.add(actionRequest, "success");
super.processAction(actionRequest, actionResponse);
}
}
view.jsp
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui"%>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
<%@ 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.");
%>
<liferay-ui:success key="success" message="Greeting saved successfully!" />
<portlet:actionURL var="editGreetingURL">
<portlet:param name="jspPage" value="/view.jsp" />
</portlet:actionURL>
<aui:form action="<%=editGreetingURL%>" method="post">
<aui:input label="greeting" name="greeting" type="text"
value="<%=greeting%>" />
<aui:button type="submit" />
</aui:form>
<portlet:renderURL var="viewGreetingURL">
<portlet:param name="jspPage" value="/view.jsp" />
</portlet:renderURL>
<p>
<a href="<%=viewGreetingURL%>">Back</a>
</p>
注:
portlet.xml要加<portlet-class>package name.java name</portlet-class>
沒有留言:
張貼留言