Liferay控制面板搜索用户分析

简介:

 在Liferay控制面板中,当在用户面板点击搜索用户时:

 

发送给服务器的请求如下:

 

我们根据struts-config.xml中的配置,找到和struts-action为/user_admin/view_users匹配的forward:

 
 
  1. <action path="/users_admin/view_users" forward="portlet.users_admin.view" /> 

 

再去tiles-def.xml中找到和forward为portlet.users_admin.view匹配的页面:

 
 
  1. <definition name="portlet.users_admin.view" extends="portlet.users_admin"> 
  2.         <put name="portlet_content" value="/portlet/users_admin/view.jsp" /> 
  3.     </definition> 

 

所以,我们找到了页面是/portlet/users_admin/view.jsp:

 
 
  1. <aui:form action="<%= portletURLString %>" method="get" name="fm"> 
  2.     <liferay-portlet:renderURLParams varImpl="portletURL" /> 
  3.     <aui:input name="<%= Constants.CMD %>" type="hidden" /> 
  4.     <aui:input name="redirect" type="hidden" value="<%= portletURLString %>" /> 
  5.  
  6.     <
  7.     long organizationGroupId = 0
  8.     %> 
  9.  
  10.     <c:if test="<%= portletName.equals(PortletKeys.USERS_ADMIN) %>"> 
  11.         <liferay-util:include page="/html/portlet/users_admin/toolbar.jsp"> 
  12.             <liferay-util:param name="toolbarItem" value="view-all" /> 
  13.         </liferay-util:include> 
  14.  
  15.         .. 

可以看出来,这个页面是个form,并且首部是toolbar.jsp(里面包含View All/Add/Export All Users),这和我们对照页面看到的不谋而合。

 

然后,它会对usersListView.equals进行判断,因为我们从浏览器中看到的信息为tree,所以执行下面代码的第15行:

 
 
  1. .. 
  2. <c:choose> 
  3.         <c:when test="<%= usersListView.equals(UserConstants.LIST_VIEW_FLAT_ORGANIZATIONS) %>"> 
  4.             <%@ include file="/html/portlet/users_admin/view_flat_organizations.jspf" %> 
  5.         </c:when> 
  6.         <c:when test="<%= usersListView.equals(UserConstants.LIST_VIEW_FLAT_USERS) %>"> 
  7.  
  8.             <
  9.             boolean organizationContextView = false
  10.             %> 
  11.  
  12.             <%@ include file="/html/portlet/users_admin/view_flat_users.jspf" %> 
  13.         </c:when> 
  14.         <c:otherwise> 
  15.             <%@ include file="/html/portlet/users_admin/view_tree.jspf" %> 
  16.         </c:otherwise> 
  17.     </c:choose> 
  18. </aui:form> 

 

我们跳转到/portlet/users_admin/view_tree.jspf文件:

我们找到了searchBar对应的代码:

 
 
  1. <span class="aui-search-bar"> 
  2.                 <aui:input inlineField="<%= true %>" label="" name="keywords" size="30" title="search-users-and-organizations" type="text" /> 
  3.  
  4.                 <aui:button onClick='<%= "javascript:" + renderResponse.getNamespace() + "search();" %>' value="search" /> 
  5.             </span> 

 

然后searchBar下方整个是一个Panel,内包含OrganizationsUsers

我们找到对应的代码,如下:

 
 
  1. <liferay-ui:panel-container extended="<%= false %>" id="usersAdminOrganizationPanelContainer" persistState="<%= true %>"> 
  2.             <%= organizationInfo %> 
  3.  
  4.             <
  5.             int usersCount = 0
  6.  
  7.             boolean showOrganizations = false
  8. ... 
  9. </liferay-ui:panel-container> 

 

然后我们继续进去找search result panel:

对应以下的图:

其代码如下:

 
 
  1. <liferay-ui:panel collapsible="<%= true %>" extended="<%= true %>" id="usersAdminUsersPanel" persistState="<%= true %>" title='<%= usersPanelTitle %>'> 
  2.  
  3.                             <
  4.                             boolean organizationContextView = true
  5.                             %> 
  6.  
  7.                             <%@ include file="/html/portlet/users_admin/view_flat_users.jspf" %> 
  8.                         </liferay-ui:panel> 

 

所以,万里长征终于走完第一步,显示所有用户信息的页面在/portlet/usrs_admin/view_flat_users.jspf中:

 
 
  1. <liferay-ui:search-container 
  2.     rowChecker="<%= new RowChecker(renderResponse) %>" 
  3.     searchContainer="<%= new UserSearch(renderRequest, portletURL) %>" 
  4. > 
  5.     <aui:input name="deleteUserIds" type="hidden" /> 
  6.     <aui:input disabled="<%= true %>" name="usersRedi 
  7. ... 
  8.  
  9.  
  10. <liferay-ui:search-container-results> 
  11.         <c:choose> 
  12.             <c:when test="<%= PropsValues.USERS_INDEXER_ENABLED && PropsValues.USERS_SEARCH_WITH_INDEX %>"> 
  13.                 <%@ include file="/html/portlet/users_admin/user_search_results_index.jspf" %> 
  14.             </c:when> 
  15.             <c:otherwise> 
  16.                 <%@ include file="/html/portlet/users_admin/user_search_results_database.jspf" %> 
  17.             </c:otherwise> 
  18.         </c:choose> 
  19.     </liferay-ui:search-container-results> 
  20.  
  21. ... 
  22. <liferay-ui:search-container-row 
  23.         className="com.liferay.portal.model.User" 
  24.         escapedModel="<%= true %>" 
  25.         keyProperty="userId" 
  26.         modelVar="user2" 
  27.     > 
  28.         <liferay-portlet:renderURL varImpl="rowURL"> 
  29.             <portlet:param name="struts_action" value="/users_admin/edit_user" /> 
  30.             <portlet:param name="redirect" value="<%= searchContainer.getIteratorURL().toString() %>" /> 
  31.             <portlet:param name="p_u_i_d" value="<%= String.valueOf(user2.getUserId()) %>" /> 
  32.         </liferay-portlet:renderURL> 
  33.  
  34.         <
  35.         if (!UserPermissionUtil.contains(permissionChecker, user2.getUserId(), ActionKeys.UPDATE)) { 
  36.             rowURL = null
  37.         } 
  38.         %> 
  39.  
  40.         <%@ include file="/html/portlet/users_admin/user/search_columns.jspf" %> 
  41.  
  42.         <liferay-ui:search-container-column-jsp 
  43.             align="right" 
  44.             path="/html/portlet/users_admin/user_action.jsp" 
  45.         /> 
  46.     </liferay-ui:search-container-row> 
  47.  
  48. .. 

 

显示不是问题,关键数据从哪里来,我们从12-17行可以看出它有一个判断:

PropsValues.USERS_INDEXER_ENABLED && PropsValues.USERS_SEARCH_WITH_INDEX 来决定它从索引还是从数据库找记录:

 

这2个值最终是配置在portal.properties文件中的:

 
 
  1.     # Set this to false to disable the user indexer. 
  2.     # 
  3.     users.indexer.enabled=true 
  4.  
  5.     # Set this to true to search users from the indexSet this to false to 
  6.     # search users from the database. Note that setting this to false will 
  7.     # disable the ability to search users based on Expando attributes. This 
  8.     # setting is not used unless the property "users.indexer.enabled" is set 
  9.     # to true
  10.     # 
  11.     users.search.with.index=true 

 

所以,我们只要在portal-ext.properties中吧这2个值设置为false,就可以让搜索的结果从数据库中来而不是索引中来。

 

大功告成。





本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/910727,如需转载请自行联系原作者

目录
相关文章
|
前端开发 小程序 关系型数据库
小程序中实现搜索功能
小程序中实现搜索功能
小程序中实现搜索功能
Win系统 - 你一直在用错误的方式搜索?(上)
Win系统 - 你一直在用错误的方式搜索?(上)
110 0
Win系统 - 你一直在用错误的方式搜索?(上)
Win系统 - 你一直在用错误的方式搜索?(下)
Win系统 - 你一直在用错误的方式搜索?(下)
81 0
Win系统 - 你一直在用错误的方式搜索?(下)
|
搜索推荐 安全 数据安全/隐私保护
Win系统 - 1903版WIN10,搜索功能将变得更好用
Win系统 - 1903版WIN10,搜索功能将变得更好用
177 0
Win系统 - 1903版WIN10,搜索功能将变得更好用
|
编译器 C语言
QT软件开发: 打开系统默认浏览器搜索内容
QT软件开发: 打开系统默认浏览器搜索内容
237 0
QT软件开发: 打开系统默认浏览器搜索内容
|
Web App开发 搜索推荐 数据库
SharePoint 无法删除搜索服务应用程序
  在SharePoint的使用中,经常会遇到某些服务创建失败,某些服务删除不成功的情况。这里,我们就遇到了搜索服务创建失败,然后删除也不成功,使用管理中心的UI无法删除,PowerShell命令也无法删除,经过很长时间的排错,终于找到解决方法。
953 0