-6ren">
gpt4 book ai didi

java - 使用 EL 传递 `` 中的值

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:49:24 25 4
gpt4 key购买 nike

我正在尝试使用 <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 来传递 value 属性。但它不起作用,我收到的值为 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 工作正常,如您所见 - ${editURL} url 属性的值,工作正常,并重定向到相应的 url。

我遇到了 this thread关于同一问题的 apache 邮件存档,但这并不能真正解决问题。

最佳答案

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

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

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

request.setAttribute("primKey", primaryKey);

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

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

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

关于java - 使用 EL 传递 `<portlet:param>` 中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17941330/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com