Reputation: 504
I can't seem to access data I want to pass to my .jsp files. I've simplified it to the bare-bones and it still doesn't work for me. This portlet is being deployed to a liferay portal.
Problem: I click on the link to call a renderURL for the next .jsp page. In the doView() method, I set an attribute with setAttribute. When I retrieve that attribute in the .jsp, it returns null.
Expected output: "Proper Value"
Actual output: "Default value"
NewPortlet.java (Controller)
public class NewPortlet extends MVCPortlet {
@Override
public void doView(RenderRequest request, RenderResponse response)
throws IOException, PortletException {
request.setAttribute("test", "Proper Value");
String path = ParamUtil
.getString(request, "path", "/html/new/view.jsp");
include(path, request, response);
}
}
view.jsp
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<portlet:renderURL var="testURL">
<portlet:param name="path" value="/html/new/edit.jsp"/>
</portlet:renderURL>
<p><a href="<%= testURL %>">Click me!</a></p>
edit.jsp
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@page import="com.liferay.portal.kernel.util.ParamUtil"%>
<portlet:defineObjects />
<%
String test = ParamUtil.getString(renderRequest, "test", "default value");
%>
<p><%= test %></p>
Upvotes: 1
Views: 2773
Reputation: 4210
I am not sure what exact usecase you have.
But here issue is, you are setting attribute and trying to fetch parameter, hence it returns null.
For solution to your issues as in code, use renderRequest.getAttribute("test")
or use el, ${test}
Upvotes: 2
Reputation: 997
The "view.jsp" is referring "edit.jsp" using portlet:renderURL
and that can be an issue. The render requests may be executed sequentially or in parallel without any guaranteed order.
I am not sure why your workflow is this way (i.e. setting parameter in doView method), but try actionURL instead of renderURL.
Upvotes: 1