Roh*_*ain 3 java jsp portlet el liferay
我正在尝试将参数传递给<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>
Run Code Online (Sandbox Code Playgroud)
如您所见,在<portlet:param>
标记中,我使用EL来传递值属性.但它不工作,我得到的价值作为0
对"resourcePrimaryKey"
我的操作方法,当我这样做:
long courseId = ParamUtil.getLong(request, "resourcePrimaryKey");
// courseId is 0 here
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用JSP表达式标签代替EL,它可以正常工作:
<portlet:actionURL name="editCourse" var="editURL">
<portlet:param name="resourcePrimaryKey" value="<%= primaryKey %>"/>
</portlet:actionURL>
Run Code Online (Sandbox Code Playgroud)
现在,我得到了所需的值"resourcePrimaryKey"
.
任何人都可以知道这里发生了什么?令人惊讶的是,EL在其他地方工作正常,如你所见 - url属性的${editURL}
值,工作正常,并重定向到相应的URL.
我在apache邮件存档上遇到了关于同一问题的这个帖子,但这并没有真正解决问题.
scriptlet中的变量不能直接在EL中使用,您首先需要将其设置为:
<c:set var="primKey"><%=primaryKey %></c:set>
Run Code Online (Sandbox Code Playgroud)
并使用${primKey}
或设置为请求属性:
request.setAttribute("primKey", primaryKey);
Run Code Online (Sandbox Code Playgroud)
显然,更好的是直接使用表达式.
同样关于${editURL}
工作,它是一个portlet jsp标记,它在页面上下文中设置变量,以便它可供EL使用.
我们的el wiki是了解这些事情的好地方,请留意Make objects available to EL
这个问题的标题:-)
归档时间: |
|
查看次数: |
5110 次 |
最近记录: |