所以我有一个搜索容器,里面有结果。该容器的最后一列是jsp列。以下是搜索容器的代码:
<%
PortletURL postsUrlPaginator = renderResponse.createRenderURL();
postsUrlPaginator.setParameter( "currentID", Long.toString( currentID ) );
postsUrlPaginator.setParameter( "jspPage", "/admin/CLAdmin.jsp" );
postsUrlPaginator.setParameter( "mainTabs", "Categories" );
%>
<liferay-ui:search-container emptyResultsMessage = "there-are-no-postings" delta = "5" iteratorURL="<%= postsUrlPaginator %>" curParam="postsUrlPaginator">
<liferay-ui:search-container-results>
<%
List<CLPosting> postings = CLPostingLocalServiceUtil.getLockedPostings( true );
results = ListUtil.subList( postings, searchContainer.getStart(), searchContainer.getEnd() );
pageContext.setAttribute( "results", results );
pageContext.setAttribute( "total", postings.size() );
%>
</liferay-ui:search-container-results>
<liferay-ui:search-container-row
className="com.camelslist.posting.model.CLPosting"
keyProperty="postID"
modelVar="posting">
<liferay-ui:search-container-column-text
name="postingTitle"
property="postTitle" />
<liferay-ui:search-container-column-text
name="locked"
property="locked" />
<liferay-ui:search-container-column-jsp
path="/admin/post/CLAdmin_post_actions.jsp" />
</liferay-ui:search-container-row>
<liferay-ui:search-iterator />
</liferay-ui:search-container>
我在最后一列中使用了一个jsp文件(CLAdmin_post_actions.jsp)来为返回的每一行生成操作按钮。我想在为每行创建这些按钮之前将值传递给该jsp文件。
<%@include file="/init.jsp" %>
<%
ResultRow row = (ResultRow) request.getAttribute( WebKeys.SEARCH_CONTAINER_RESULT_ROW );
CLPosting posting = (CLPosting) row.getObject();
long groupId = themeDisplay.getLayout().getGroupId();
String name = CLPosting.class.getName();
String primeKey = String.valueOf( posting.getPrimaryKey() );
System.out.println( "posting: " + posting.getPostTitle() + " : " + "ID: " + Long.toString( posting.getPrimaryKey() ) );
long currentID = posting.getCategoryID();
CLCategory category = ( currentID != Long.valueOf( 0 ) ) ? CLCategoryLocalServiceUtil.getCLCategory( currentID ) : null;
long parentCatID = ( category != null ) ? category.getParentID() : Long.valueOf( 0 );
%>
<liferay-ui:icon-menu>
<c:if test = "<%= permissionChecker.hasPermission( groupId, name, primeKey, ActionKeys.DELETE ) %>" >
<portlet:actionURL name="deletePosting" var="deleteURL">
<portlet:param name="resourcePrimeKey" value="<%= primeKey %>" />
<portlet:param name="currentID" value="<%= Long.toString( currentID ) %>" />
</portlet:actionURL>
<liferay-ui:icon-delete url="<%= deleteURL.toString() %>" />
</c:if>
<c:if test="<%= permissionChecker.hasPermission(groupId, name, primeKey, ActionKeys.VIEW) %>" >
</c:if>
<c:if test="<%= permissionChecker.hasPermission(groupId, name, primeKey, ActionKeys.UPDATE) %>" >
<c:if test="<%= posting.getLocked() == false %>" >
<portlet:actionURL name="lockPosting" var="lockURL">
<portlet:param name="resourcePrimeKey" value="<%= primeKey %>" />
<portlet:param name="currentID" value="<%= Long.toString( currentID ) %>" />
<portlet:param name="mainTabs" value="Categories" />
<portlet:param name="lock" value="true" />
</portlet:actionURL>
<liferay-ui:icon image="lock" url="<%= lockURL.toString() %>" />
</c:if>
<c:if test="<%= posting.getLocked() == true %>" >
<portlet:actionURL name="lockPosting" var="lockURL">
<portlet:param name="resourcePrimeKey" value="<%= primeKey %>" />
<portlet:param name="currentID" value="<%= Long.toString( currentID ) %>" />
<portlet:param name="mainTabs" value="Categories" />
<portlet:param name="lock" value="false" />
</portlet:actionURL>
<liferay-ui:icon image="unlock" url="<%= lockURL.toString() %>" />
</c:if>
</c:if>
<c:if test = "<%= permissionChecker.hasPermission( groupId, name, primeKey, ActionKeys.PERMISSIONS) %>">
<liferay-security:permissionsURL
modelResource="<%= CLPosting.class.getName() %>"
modelResourceDescription="<%= posting.getPostTitle() %>"
resourcePrimKey="<%= primeKey %>"
var="permissionsURL" />
<liferay-ui:icon image="permissions" url="<%= permissionsURL.toString() %>" />
</c:if>
</liferay-ui:icon-menu>
我该怎么办?我可以这样做吗?
答案 0 :(得分:0)
我实际上自己回答了这个问题,答案非常明显(对于我认为经验丰富的portlet开发人员而言)。
我试图通过参数传递所需的值。当我使用servlets属性时,我能够获得所需的值。
以上是为了使这个答案更加明确而添加到上面的代码:
<%
//NEW LINES ADDED
String mainTabs = ParamUtil.getString( request, "mainTabs", "Categories" );
request.setAttribute( "mainTabs", mainTabs );
PortletURL postsUrlPaginator = renderResponse.createRenderURL();
postsUrlPaginator.setParameter( "currentID", Long.toString( currentID ) );
postsUrlPaginator.setParameter( "jspPage", "/admin/CLAdmin.jsp" );
postsUrlPaginator.setParameter( "mainTabs", "Categories" );
%>
//... additional code not shown
然后在CLAdmin_actions.jsp中在顶部添加以下行以检索我们的值:
String mainTabs = (String) request.getAttribute( "mainTabs" );