是否可以使 liferay-ui:search-container 行在 Life ray 中不可编辑?
Can it possible to make liferay-ui:search-container rows as non editable in Life ray?
我有一个页面需要在我的自定义 portlet 中设置为用户分配站点角色。因此,我能够在一个列表中获取 "User existing roles",在另一个列表中获取所有 "Available site roles"。那么我该如何进行调节或者我需要对已分配给用户的行进行不可编辑的任何验证。比方说(我们有四个站点类型角色,即站点管理员、站点所有者、站点成员和站点内容审阅者现在相应的用户已经分配了站点管理员角色。所以现在在搜索容器行中我需要创建站点管理员行不可编辑,因为用户已经拥有此角色)。我的代码如下,
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@include file="/html/users/init.jsp"%>
<portletefineObjects />
<%
List<Role> siteRoleList = (List) request.getAttribute("allsiteRolesList");
List<Role> existingRoles = (List) request.getAttribute("existingRoles");
String sel_userID = renderRequest.getParameter("sel_userID");
String backURL = ParamUtil.getString(request, "backURL");
%>
<%!
List<Role> roles = null;
int totalNoOfroles=0;
String value = null;
%>
<%
totalNoOfroles = siteRoleList.size();
roles = siteRoleList;
%>
<liferay-ui:header backURL="<%= backURL %>" title="Available Site Roles" />
<liferay-ui:search-container delta="5" emptyResultsMessage="no-site-roles-were-found" rowChecker="<%= new RowChecker(renderResponse) %>" >
<liferay-ui:search-container-results
results="<%= ListUtil.subList(roles,searchContainer.getStart(),searchContainer.getEnd()) %>"
total="<%= totalNoOfroles %>">
</liferay-ui:search-container-results>
<liferay-ui:search-container-row className="com.liferay.portal.model.Role" keyProperty="roleId" modelVar="role">
<liferay-ui:search-container-row-parameter name="roleIds" value="<%= role.getRoleId() %>"></liferay-ui:search-container-row-parameter>
<liferay-ui:search-container-row-parameter name="userIds" value="<%= sel_userID %>"></liferay-ui:search-container-row-parameter>
<liferay-ui:search-container-column-text name="title" value="<%= role.getName()%>" />
<liferay-ui:search-container-column-text name="type" value="<%= role.getTypeLabel() %>">
</liferay-ui:search-container-column-text>
<liferay-ui:search-container-column-text name="description" value="<%= role.getDescription() %>">
</liferay-ui:search-container-column-text>
<liferay-ui:search-container-column-jsp align="right" path="/html/users/user_assign_site_role_actions.jsp" />
</liferay-ui:search-container-row>
<liferay-ui:search-iterator />
</liferay-ui:search-container>
<liferay-ui:search-container delta="5" emptyResultsMessage="no-users-were-found" />
动作Class:
public void assignUserSiteRoles(ActionRequest request, ActionResponse response) throws com.liferay.portal.kernel.exception.PortalException, com.liferay.portal.kernel.exception.SystemException{
String sel_userID = ParamUtil.getString(request, "selectedId");
long userid = Long.valueOf(sel_userID);
String backURL = ParamUtil.getString(request, "backURL");
ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
long companyId = themeDisplay.getCompanyId();
long mySite = themeDisplay.getSiteGroupId();
List<Role> allsiteRolesList = new ArrayList<Role>();
List<Role> existing roles = new ArrayList<Role>();
List<UserGroupRole> userGroupRoleList = UserGroupRoleLocalServiceUtil.getUserGroupRoles(userid, mySite);
if (userGroupRoleList != null) {
for (UserGroupRole userGroupRole : userGroupRoleList) {
/* Get Role object based on userGroupRole.getRoleId() */
Role role = RoleLocalServiceUtil.getRole(userGroupRole.getRoleId());
if(role.getTypeLabel().equalsIgnoreCase("Site"))
{
existingroles.add(role);
}
}
}
List<Role> rolesList = RoleLocalServiceUtil.getRoles(companyId);
if (rolesList != null) {
for (Role role : rolesList) {
if(role.getTypeLabel().equalsIgnoreCase("Site"))
{
allsiteRolesList.add(role);
}
}
}
request.setAttribute("allsiteRolesList", allsiteRolesList);
response.setRenderParameter("sel_userID", sel_userID);
response.setRenderParameter("backURL", backURL);
response.setRenderParameter("mvcPath","/html/users/assign_user_site_roles.jsp");
}
在我的代码中,siteRoleList
包含所有可用角色的列表,existingRoles
列表包含已为相应用户分配的角色。那么如何才能只对用户具有该角色的那些行进行编辑。
actionJSP
<%@ include file="/html/users/init.jsp" %>
<%
ResultRow resultRow = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
Role role = (Role)resultRow.getObject();
String rowUserId = (String)resultRow.getParameter("userIds");
%>
<liferay-ui:icon-menu>
<portlet:actionURL name="UserSiteRoleAssign" var="UserSiteRoleAssign">
<portlet:param name="selectedId" value="<%=String.valueOf(role.getRoleId()) %>" />
<portle:pgaram name="rowUserId" value="<%= rowUserId %>" />
</portlet:actionURL>
<liferay-ui:icon iconCssClass="icon-signin" message="Assign Role" url="<%= UserSiteRoleAssign.toString() %>" />
</liferay-ui:icon-menu>
有什么建议请..
我不确定您如何评估条件以检查特定用户是否具有该特定角色。
无论如何,在您 actionJSP
中,如果您可以通过检查 existingRoles 列表来设法识别所选用户具有该特定角色,如下所示,应该为您解决问题:
<%
ResultRow resultRow = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
Role role = (Role)resultRow.getObject();
String rowUserId = (String)resultRow.getParameter("userIds");
/* Get user existingRoles list here. */
boolean hasSiteRole = false;
for(Role userRole : existingRoles){
if(userRole.getRoleId() == role.getRoleId())
hasSiteRole = true;
}
%>
<liferay-ui:icon-menu>
<portlet:actionURL name="UserSiteRoleAssign" var="UserSiteRoleAssign">
<portlet:param name="selectedId" value="<%=String.valueOf(role.getRoleId()) %>" />
<portle:pgaram name="rowUserId" value="<%= rowUserId %>" />
</portlet:actionURL>
<%
String url = !hasSiteRole ? UserSiteRoleAssign.toString() : "javascript: void();";
String styleClass = !hasSiteRole ? "icon-signin" : "icon-signin-diabled";
%>
<liferay-ui:icon iconCssClass="<%=styleClass %>" message="Assign Role" url="<%=url %>" />
</liferay-ui:icon-menu>
在hasSiteRole
属性的基础上,您可以控制图标href
、class
或rendering
。您也可以在主视图中查看。将图标和样式 class 隐藏为禁用,以防 existingRoles 列表中的用户已存在特定角色。
注意:这只是一个想法,还得具体实现。
我有一个页面需要在我的自定义 portlet 中设置为用户分配站点角色。因此,我能够在一个列表中获取 "User existing roles",在另一个列表中获取所有 "Available site roles"。那么我该如何进行调节或者我需要对已分配给用户的行进行不可编辑的任何验证。比方说(我们有四个站点类型角色,即站点管理员、站点所有者、站点成员和站点内容审阅者现在相应的用户已经分配了站点管理员角色。所以现在在搜索容器行中我需要创建站点管理员行不可编辑,因为用户已经拥有此角色)。我的代码如下,
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@include file="/html/users/init.jsp"%>
<portletefineObjects />
<%
List<Role> siteRoleList = (List) request.getAttribute("allsiteRolesList");
List<Role> existingRoles = (List) request.getAttribute("existingRoles");
String sel_userID = renderRequest.getParameter("sel_userID");
String backURL = ParamUtil.getString(request, "backURL");
%>
<%!
List<Role> roles = null;
int totalNoOfroles=0;
String value = null;
%>
<%
totalNoOfroles = siteRoleList.size();
roles = siteRoleList;
%>
<liferay-ui:header backURL="<%= backURL %>" title="Available Site Roles" />
<liferay-ui:search-container delta="5" emptyResultsMessage="no-site-roles-were-found" rowChecker="<%= new RowChecker(renderResponse) %>" >
<liferay-ui:search-container-results
results="<%= ListUtil.subList(roles,searchContainer.getStart(),searchContainer.getEnd()) %>"
total="<%= totalNoOfroles %>">
</liferay-ui:search-container-results>
<liferay-ui:search-container-row className="com.liferay.portal.model.Role" keyProperty="roleId" modelVar="role">
<liferay-ui:search-container-row-parameter name="roleIds" value="<%= role.getRoleId() %>"></liferay-ui:search-container-row-parameter>
<liferay-ui:search-container-row-parameter name="userIds" value="<%= sel_userID %>"></liferay-ui:search-container-row-parameter>
<liferay-ui:search-container-column-text name="title" value="<%= role.getName()%>" />
<liferay-ui:search-container-column-text name="type" value="<%= role.getTypeLabel() %>">
</liferay-ui:search-container-column-text>
<liferay-ui:search-container-column-text name="description" value="<%= role.getDescription() %>">
</liferay-ui:search-container-column-text>
<liferay-ui:search-container-column-jsp align="right" path="/html/users/user_assign_site_role_actions.jsp" />
</liferay-ui:search-container-row>
<liferay-ui:search-iterator />
</liferay-ui:search-container>
<liferay-ui:search-container delta="5" emptyResultsMessage="no-users-were-found" />
动作Class:
public void assignUserSiteRoles(ActionRequest request, ActionResponse response) throws com.liferay.portal.kernel.exception.PortalException, com.liferay.portal.kernel.exception.SystemException{
String sel_userID = ParamUtil.getString(request, "selectedId");
long userid = Long.valueOf(sel_userID);
String backURL = ParamUtil.getString(request, "backURL");
ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
long companyId = themeDisplay.getCompanyId();
long mySite = themeDisplay.getSiteGroupId();
List<Role> allsiteRolesList = new ArrayList<Role>();
List<Role> existing roles = new ArrayList<Role>();
List<UserGroupRole> userGroupRoleList = UserGroupRoleLocalServiceUtil.getUserGroupRoles(userid, mySite);
if (userGroupRoleList != null) {
for (UserGroupRole userGroupRole : userGroupRoleList) {
/* Get Role object based on userGroupRole.getRoleId() */
Role role = RoleLocalServiceUtil.getRole(userGroupRole.getRoleId());
if(role.getTypeLabel().equalsIgnoreCase("Site"))
{
existingroles.add(role);
}
}
}
List<Role> rolesList = RoleLocalServiceUtil.getRoles(companyId);
if (rolesList != null) {
for (Role role : rolesList) {
if(role.getTypeLabel().equalsIgnoreCase("Site"))
{
allsiteRolesList.add(role);
}
}
}
request.setAttribute("allsiteRolesList", allsiteRolesList);
response.setRenderParameter("sel_userID", sel_userID);
response.setRenderParameter("backURL", backURL);
response.setRenderParameter("mvcPath","/html/users/assign_user_site_roles.jsp");
}
在我的代码中,siteRoleList
包含所有可用角色的列表,existingRoles
列表包含已为相应用户分配的角色。那么如何才能只对用户具有该角色的那些行进行编辑。
actionJSP
<%@ include file="/html/users/init.jsp" %>
<%
ResultRow resultRow = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
Role role = (Role)resultRow.getObject();
String rowUserId = (String)resultRow.getParameter("userIds");
%>
<liferay-ui:icon-menu>
<portlet:actionURL name="UserSiteRoleAssign" var="UserSiteRoleAssign">
<portlet:param name="selectedId" value="<%=String.valueOf(role.getRoleId()) %>" />
<portle:pgaram name="rowUserId" value="<%= rowUserId %>" />
</portlet:actionURL>
<liferay-ui:icon iconCssClass="icon-signin" message="Assign Role" url="<%= UserSiteRoleAssign.toString() %>" />
</liferay-ui:icon-menu>
有什么建议请..
我不确定您如何评估条件以检查特定用户是否具有该特定角色。
无论如何,在您 actionJSP
中,如果您可以通过检查 existingRoles 列表来设法识别所选用户具有该特定角色,如下所示,应该为您解决问题:
<%
ResultRow resultRow = (ResultRow)request.getAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
Role role = (Role)resultRow.getObject();
String rowUserId = (String)resultRow.getParameter("userIds");
/* Get user existingRoles list here. */
boolean hasSiteRole = false;
for(Role userRole : existingRoles){
if(userRole.getRoleId() == role.getRoleId())
hasSiteRole = true;
}
%>
<liferay-ui:icon-menu>
<portlet:actionURL name="UserSiteRoleAssign" var="UserSiteRoleAssign">
<portlet:param name="selectedId" value="<%=String.valueOf(role.getRoleId()) %>" />
<portle:pgaram name="rowUserId" value="<%= rowUserId %>" />
</portlet:actionURL>
<%
String url = !hasSiteRole ? UserSiteRoleAssign.toString() : "javascript: void();";
String styleClass = !hasSiteRole ? "icon-signin" : "icon-signin-diabled";
%>
<liferay-ui:icon iconCssClass="<%=styleClass %>" message="Assign Role" url="<%=url %>" />
</liferay-ui:icon-menu>
在hasSiteRole
属性的基础上,您可以控制图标href
、class
或rendering
。您也可以在主视图中查看。将图标和样式 class 隐藏为禁用,以防 existingRoles 列表中的用户已存在特定角色。
注意:这只是一个想法,还得具体实现。