是否有可能使liferay-ui:搜索容器行在Life ray中不可编辑?

时间:2015-04-16 15:35:51

标签: liferay hook liferay-6 liferay-theme liferay-aui

我有一个页面,我需要在自定义portlet中为用户设置分配站点角色。所以我能够获得"用户现有角色"在一个列表和所有"可用站点角色"在另一个清单中。那么我该如何进行调节或者我需要对用户已分配的行进行不可编辑的任何验证。让我们说(我们有四个站点类型角色,即站点管理员,站点所有者,站点成员和站点内容审阅者现在相应的用户已经分配了站点管理员角色。所以现在在搜索容器行中我需要制作站点管理员行不可编辑,因为用户已具有此角色)。我的代码如下,

 <%@ 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" />

行动类:

 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>

请提出任何建议..

1 个答案:

答案 0 :(得分:0)

我不确定您如何评估条件以检查某个用户是否具有该特定角色。

无论如何,在您actionJSP中,如果您可以通过检查现有的列表列表来确定所选用户具有该特定角色,那么应该为您做好准备:

<%
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属性,您可以为图标控制hrefclassrendering。您也可以在主视图上查看。如果现有角色列表中的用户已存在某个角色,则将图标和样式类隐藏为已禁用。

注意:这只是一个想法,你必须给它具体的实现。