编程语言
首页 > 编程语言> > java – 在“使用EL中传递值

java – 在“使用EL中传递值

作者:互联网

我正在尝试使用< 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传递值属性.但它不起作用,我在动作方法中收到“resourcePrimaryKey”的值为0,当我这样做时:

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邮件存档上遇到了关于同一问题的this thread,但这并没有真正解决问题.

解决方法:

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

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

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

request.setAttribute("primKey", primaryKey);

显然,更好的是直接使用表达式.

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

我们的 wiki是一个了解这些东西的好地方,请注意标题为EL提供这个问题的对象:-)

标签:portlet,java,jsp,el,liferay,el
来源: https://codeday.me/bug/20190831/1777439.html