在Liferay控制面板中,当在用户面板点击搜索用户时:
发送给服务器的请求如下:
我们根据struts-config.xml中的配置,找到和struts-action为/user_admin/view_users匹配的forward:
- <action path="/users_admin/view_users" forward="portlet.users_admin.view" />
再去tiles-def.xml中找到和forward为portlet.users_admin.view匹配的页面:
- <definition name="portlet.users_admin.view" extends="portlet.users_admin">
- <put name="portlet_content" value="/portlet/users_admin/view.jsp" />
- </definition>
所以,我们找到了页面是/portlet/users_admin/view.jsp:
- <aui:form action="<%= portletURLString %>" method="get" name="fm">
- <liferay-portlet:renderURLParams varImpl="portletURL" />
- <aui:input name="<%= Constants.CMD %>" type="hidden" />
- <aui:input name="redirect" type="hidden" value="<%= portletURLString %>" />
- <%
- long organizationGroupId = 0;
- %>
- <c:if test="<%= portletName.equals(PortletKeys.USERS_ADMIN) %>">
- <liferay-util:include page="/html/portlet/users_admin/toolbar.jsp">
- <liferay-util:param name="toolbarItem" value="view-all" />
- </liferay-util:include>
- ..
可以看出来,这个页面是个form,并且首部是toolbar.jsp(里面包含View All/Add/Export All Users),这和我们对照页面看到的不谋而合。
然后,它会对usersListView.equals进行判断,因为我们从浏览器中看到的信息为tree,所以执行下面代码的第15行:
- ..
- <c:choose>
- <c:when test="<%= usersListView.equals(UserConstants.LIST_VIEW_FLAT_ORGANIZATIONS) %>">
- <%@ include file="/html/portlet/users_admin/view_flat_organizations.jspf" %>
- </c:when>
- <c:when test="<%= usersListView.equals(UserConstants.LIST_VIEW_FLAT_USERS) %>">
- <%
- boolean organizationContextView = false;
- %>
- <%@ include file="/html/portlet/users_admin/view_flat_users.jspf" %>
- </c:when>
- <c:otherwise>
- <%@ include file="/html/portlet/users_admin/view_tree.jspf" %>
- </c:otherwise>
- </c:choose>
- </aui:form>
我们跳转到/portlet/users_admin/view_tree.jspf文件:
我们找到了searchBar对应的代码:
- <span class="aui-search-bar">
- <aui:input inlineField="<%= true %>" label="" name="keywords" size="30" title="search-users-and-organizations" type="text" />
- <aui:button onClick='<%= "javascript:" + renderResponse.getNamespace() + "search();" %>' value="search" />
- </span>
然后searchBar下方整个是一个Panel,内包含Organizations和Users:
我们找到对应的代码,如下:
- <liferay-ui:panel-container extended="<%= false %>" id="usersAdminOrganizationPanelContainer" persistState="<%= true %>">
- <%= organizationInfo %>
- <%
- int usersCount = 0;
- boolean showOrganizations = false;
- ...
- </liferay-ui:panel-container>
然后我们继续进去找search result panel:
对应以下的图:
其代码如下:
- <liferay-ui:panel collapsible="<%= true %>" extended="<%= true %>" id="usersAdminUsersPanel" persistState="<%= true %>" title='<%= usersPanelTitle %>'>
- <%
- boolean organizationContextView = true;
- %>
- <%@ include file="/html/portlet/users_admin/view_flat_users.jspf" %>
- </liferay-ui:panel>
所以,万里长征终于走完第一步,显示所有用户信息的页面在/portlet/usrs_admin/view_flat_users.jspf中:
- <liferay-ui:search-container
- rowChecker="<%= new RowChecker(renderResponse) %>"
- searchContainer="<%= new UserSearch(renderRequest, portletURL) %>"
- >
- <aui:input name="deleteUserIds" type="hidden" />
- <aui:input disabled="<%= true %>" name="usersRedi
- ...
- <liferay-ui:search-container-results>
- <c:choose>
- <c:when test="<%= PropsValues.USERS_INDEXER_ENABLED && PropsValues.USERS_SEARCH_WITH_INDEX %>">
- <%@ include file="/html/portlet/users_admin/user_search_results_index.jspf" %>
- </c:when>
- <c:otherwise>
- <%@ include file="/html/portlet/users_admin/user_search_results_database.jspf" %>
- </c:otherwise>
- </c:choose>
- </liferay-ui:search-container-results>
- ...
- <liferay-ui:search-container-row
- className="com.liferay.portal.model.User"
- escapedModel="<%= true %>"
- keyProperty="userId"
- modelVar="user2"
- >
- <liferay-portlet:renderURL varImpl="rowURL">
- <portlet:param name="struts_action" value="/users_admin/edit_user" />
- <portlet:param name="redirect" value="<%= searchContainer.getIteratorURL().toString() %>" />
- <portlet:param name="p_u_i_d" value="<%= String.valueOf(user2.getUserId()) %>" />
- </liferay-portlet:renderURL>
- <%
- if (!UserPermissionUtil.contains(permissionChecker, user2.getUserId(), ActionKeys.UPDATE)) {
- rowURL = null;
- }
- %>
- <%@ include file="/html/portlet/users_admin/user/search_columns.jspf" %>
- <liferay-ui:search-container-column-jsp
- align="right"
- path="/html/portlet/users_admin/user_action.jsp"
- />
- </liferay-ui:search-container-row>
- ..
显示不是问题,关键数据从哪里来,我们从12-17行可以看出它有一个判断:
PropsValues.USERS_INDEXER_ENABLED && PropsValues.USERS_SEARCH_WITH_INDEX 来决定它从索引还是从数据库找记录:
这2个值最终是配置在portal.properties文件中的:
- #
- # Set this to false to disable the user indexer.
- #
- users.indexer.enabled=true
- # Set this to true to search users from the index. Set this to false to
- # search users from the database. Note that setting this to false will
- # disable the ability to search users based on Expando attributes. This
- # setting is not used unless the property "users.indexer.enabled" is set
- # to true.
- #
- users.search.with.index=true
所以,我们只要在portal-ext.properties中吧这2个值设置为false,就可以让搜索的结果从数据库中来而不是索引中来。
大功告成。