Reputation: 213213
I'm trying to pass a parameter with <portlet:actionURL>
to a portlet in liferay, but it turns out that, using EL to pass values in not working, however, using JSP expression tag is working fine.
Here's my relevant code:
<%
ResultRow row = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
Course course = (Course) row.getObject();
long groupId = themeDisplay.getLayout().getGroupId();
String name = Course.class.getName();
String primaryKey = String.valueOf(course.getPrimaryKey());
%>
<liferay-ui:icon-menu>
<c:if test="<%= permissionChecker.hasPermission(groupId, name, primaryKey, ActionKeys.UPDATE)%>">
<portlet:actionURL name="editCourse" var="editURL">
<portlet:param name="resourcePrimaryKey" value="${primaryKey}"/>
</portlet:actionURL>
<liferay-ui:icon image="edit" message="Edit" url="${editURL}" />
</c:if>
</liferay-ui:icon-menu>
As you see, in <portlet:param>
tag, I have used EL for passing value attribute. But it doesn't work, and I receive the value as 0
for "resourcePrimaryKey"
in my action method, when I do:
long courseId = ParamUtil.getLong(request, "resourcePrimaryKey");
// courseId is 0 here
However, if I use JSP expression tag in place of EL, it works fine:
<portlet:actionURL name="editCourse" var="editURL">
<portlet:param name="resourcePrimaryKey" value="<%= primaryKey %>"/>
</portlet:actionURL>
Now, I get the required value for "resourcePrimaryKey"
.
Can anyone figure what's going on here? Surprisingly, EL at other place work fine, as you see - ${editURL}
value for url attribute, is working fine, and redirecting to the corresponding url.
I came across this thread on apache mail archive regarding the same issue, but that doesn't really solve the problem.
Upvotes: 3
Views: 5732
Reputation: 11698
A variable in the scriptlet cannot be used directly in an EL, you would first need to set it like:
<c:set var="primKey"><%=primaryKey %></c:set>
and use ${primKey}
or set it as a request attribute:
request.setAttribute("primKey", primaryKey);
Clearly, better would be to directly use the expression.
Also regarding the ${editURL}
working, it is a portlet jsp tag which sets the variable in the page context so that it is available to the EL.
Our el wiki is a good place to know these things, look out for the heading Make objects available to EL
for this question :-)
Upvotes: 6