I have a page where I need to set assign the site roles for user in my custom portlet. So I am able to get the "User existing roles" in one list and all "Available site roles" in another list. So how can I do conditioning Or any validation that I need to make non editable for the rows which user has been assigned. Let's say( we have four site type roles i.e, Site Administrator, Site Owner, Site Member and Site Content Reviewer Now the respective user has already assigned with Site Administrator role. So Now In the search container rows I need to make the Site Administrator row as non editable because the user has already has this role). My code is as follows,
<%@ 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" />
Action 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");
}
In my code, siteRoleList
has list of all available roles and existingRoles
list has roles which has already assigned for that respective user. So how can make editable for only those rows which user does's have that roles.
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>
Any suggestions please..