我创建了一个portlet,我以编程方式添加用户。我现在可以添加和查看用户。为了编辑我创建的用户<liferay-ui:icon-menu>
并添加了两个选项(编辑和取消激活)。现在,在单击或选择相应的用户操作按钮(编辑/取消激活)时,我需要将所选的用户ID发送到我的操作类。一旦我在动作类中获得了userID,我将使用更新的值调用UserLocalServiceUtil.updateUser()
方法。任何人都可以告诉我如何将选定的用户ID发送到我的动作类。
我的代码如下,
view.jsp的
<liferay-ui:search-container delta="10" emptyResultsMessage="no-users-were-found">
<liferay-ui:search-container-results
results="<%=UserLocalServiceUtil.getUsers(searchContainer.getStart(), searchContainer.getEnd())%>"
total="<%=UserLocalServiceUtil.getUsersCount()%>" />
<liferay-ui:search-container-row className="com.liferay.portal.model.User" keyProperty="userId" modelVar="user">
<liferay-ui:search-container-column-text name="name" value="<%= user.getFullName() %>"/>
<liferay-ui:search-container-column-text name="first-name" property="firstName" />
<liferay-ui:search-container-column-text name="last-name" property="lastName" />
<liferay-ui:search-container-column-text name="screen-name" property="screenName"/>
<liferay-ui:search-container-column-jsp align="right" path="/html/users/custom_user_actions.jsp" />
</liferay-ui:search-container-row>
<liferay-ui:search-iterator />
</liferay-ui:search-container>
<liferay-ui:search-container delta="10" emptyResultsMessage="no-users-were-found" />
custom_user_actions.jsp
<liferay-ui:icon-menu>
<portlet:actionURL name="edit" var="edit">
<portletaram name="action" value="edit" />
</portlet:actionURL>
<liferay-ui:icon image="edit" message="Edit" url="<%=edit.toString() %>" />
<portlet:actionURL name="deactivate" var="deactivate">
<portletaram name="action" value="deactivate" />
</portlet:actionURL>
<liferay-ui:icon image="deactivate" message="deactivate" url="<%= deactivate.toString() %>" />
</liferay-ui:icon-menu>
动作类
public void edit(ActionRequest request, ActionResponse response) throws com.liferay.portal.kernel.exception.PortalException, com.liferay.portal.kernel.exception.SystemException{
System.out.println("<<<< Controller add() method has been called >>>>>>>>>");
}
public void deactivate(ActionRequest request, ActionResponse response) throws com.liferay.portal.kernel.exception.PortalException, com.liferay.portal.kernel.exception.SystemException{
System.out.println("<<<< Controller delete() method has been called >>>>>>>>>");
}
任何人都可以建议我如何将选定的行用户ID传递给我的动作类。
提前致谢。
答案 0 :(得分:2)
在custom_user_actions.jsp
中获取相应的userId,并将其作为参数传递给您的操作类。
在custom_user_actions.jsp
<%
ResultRow resultRow = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
User userObj = (User)resultRow.getObject();
%>
并按如下方式传递参数,
<portlet:actionURL name="edit" var="edit">
<portletaram name="selectedId" value="<%String.valueOf(user.getUserId())%>" />
</portlet:actionURL>
<liferay-ui:icon image="edit" message="Edit" url="<%=edit.toString() %>" />
获取动作类中的参数,
public void edit(ActionRequest request, ActionResponse response) throws com.liferay.portal.kernel.exception.PortalException, com.liferay.portal.kernel.exception.SystemException{
String usrID = ParamUtil.getString(request, "selectedId")
System.out.println("<<<< Controller add() method has been called >>>>>>>>>");
}
希望它可以帮助你:)