Reputation: 574
I'm working with portlets and was working through the sample on liferay's wiki: https://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/writing-the-my-greeting-portl-4
I'm having some issues with the portlet redirecting back to the init jsp after processing a form. My Java class is:
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 Directory 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);
}
}
I have two jsps. 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="mvcPath" value="/edit.jsp" />
</portlet:renderURL>
<p><a href="<%= editGreetingURL %>">Edit greeting</a></p>
And edit.jsp:
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ 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="mvcPath" value="/edit.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="mvcPath" value="/view.jsp" />
</portlet:renderURL>
<p><a href="<%= viewGreetingURL %>">← Back</a></p>
On the form submit of the edit.jsp, it's supposed to re-render that page. When I just use portlet:renderUrl instead of portlet:actionUrl, it does it correctly, but actionUrl isn't re-rendering. The tutorial says that it IS supposed to render edit.jsp again, so I'm not sure what I'm missing. Note: It is saving all my parameters correctly.
Upvotes: 1
Views: 4362
Reputation: 967
According to the JSR 286 (aka Portlet Specification 2.0), PLT.11.1.1.2:
The portlet-container must not propagate parameters received in an action or event request to subsequent render requests of the portlet.
This is what happens when the user clicks the Submit button on the browser page:
processAction
method.processAction
method terminates without errors, Liferay is still responding to the Action request and the browser is still waiting for a response, which will be the HTML of the current page.render
method for every portlet in page. That is, if makes a Render request to these portlets.MVCPortlet
, the render
method reads the "mvcPath" parameter to find out which JSP page it has to render.But now, the JSR 286 says that there's no parameter passing between the Action and the Render phases, so the mvcPath
, which was part of the Action request, is not copied by Liferay to the Render request that Liferay makes to your portlet.
Now, solutions:
processAction
method (but usually you don't change the processAction
method, instead you create different methods for different actions, they'll tell you how to do in the tutorials... have a look to http://dev.liferay.com), you can set actionResponse.setRenderParameter("mvcPath","/edit.jsp")
. This is perfectly normal.copy-request-parameters
init parameter to true
(have a look here)Sorry, there's a lot to say about this subject, hope what I wrote can be useful to you!
Upvotes: 3