3

我正在尝试将参数传递给<portlet:actionURL>liferay 中的portlet,但事实证明,使用EL 传递值不起作用,但是,使用JSP 表达式标记工作正常。

这是我的相关代码:

<%
    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>

如您所见,在<portlet:param>标记中,我使用 EL 来传递属性。但它不起作用,当我这样做时,我会在我的操作方法中0收到值:"resourcePrimaryKey"

long courseId = ParamUtil.getLong(request, "resourcePrimaryKey");
// courseId is 0 here

但是,如果我使用 JSP 表达式标记代替 EL,它可以正常工作:

<portlet:actionURL name="editCourse" var="editURL">
    <portlet:param name="resourcePrimaryKey" value="<%= primaryKey %>"/>
</portlet:actionURL>

现在,我得到了所需的值"resourcePrimaryKey"

谁能弄清楚这里发生了什么?令人惊讶的是,如您所见,其他地方的 EL 工作正常 - url${editURL}属性的值工作正常,并重定向到相应的 url。

我在 apache 邮件存档上遇到了这个关于同一问题的线程,但这并不能真正解决问题。

4

1 回答 1

6

scriptlet 中的变量不能直接在 EL 中使用,您首先需要将其设置为:

<c:set var="primKey"><%=primaryKey %></c:set>

并将其使用${primKey}或设置为请求属性:

request.setAttribute("primKey", primaryKey);

显然,最好直接使用表达式。

同样关于${editURL}工作,它是一个portlet jsp 标记,它在页面上下文中设置变量,以便EL 可以使用它。

我们的 wiki 是了解这些事情的好地方,请留意Make objects available to EL这个问题的标题 :-)

于 2013-07-30T09:07:32.513 回答