如何将选定的 userId 传递给操作 class?
how to pass selected userId to action class?
我创建了一个 portlet,我在其中以编程方式添加用户。我现在可以添加和查看用户。为了编辑用户,我创建了 <liferay-ui:icon-menu>
并添加了两个选项(编辑和停用)。现在单击或选择相应的用户操作按钮(编辑/停用)后,我需要将选定的用户 ID 发送到我的操作 class。在我的操作 class 中获得用户 ID 后,我将使用更新后的值调用 UserLocalServiceUtil.updateUser()
方法。谁能告诉我如何将选定的用户 ID 发送到我的操作 class.
我的代码如下,
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>
操作class
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 传递给我的操作 class。
提前致谢。
在 custom_user_actions.jsp
中获取相应的 userId 并将其作为参数传递给您的操作 class。
在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() %>" />
在您的操作中获取参数 class as,
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 >>>>>>>>>");
}
希望对您有所帮助:)
我创建了一个 portlet,我在其中以编程方式添加用户。我现在可以添加和查看用户。为了编辑用户,我创建了 <liferay-ui:icon-menu>
并添加了两个选项(编辑和停用)。现在单击或选择相应的用户操作按钮(编辑/停用)后,我需要将选定的用户 ID 发送到我的操作 class。在我的操作 class 中获得用户 ID 后,我将使用更新后的值调用 UserLocalServiceUtil.updateUser()
方法。谁能告诉我如何将选定的用户 ID 发送到我的操作 class.
我的代码如下,
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>
操作class
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 传递给我的操作 class。
提前致谢。
在 custom_user_actions.jsp
中获取相应的 userId 并将其作为参数传递给您的操作 class。
在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() %>" />
在您的操作中获取参数 class as,
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 >>>>>>>>>");
}
希望对您有所帮助:)