当在Dockbar上点击Add->More...后,就进入了layout_configuration:
这也是一个portlet(Liferay内核中的一个特殊的portlet),portlet_id为87,参见liferay-portlet.xml:
- <portlet>
- <portlet-name>87</portlet-name>
- <icon>/html/icons/default.png</icon>
- <struts-path>layout_configuration</struts-path>
- <use-default-template>false</use-default-template>
- <show-portlet-access-denied>false</show-portlet-access-denied>
- <show-portlet-inactive>false</show-portlet-inactive>
- <private-request-attributes>false</private-request-attributes>
- <private-session-attributes>false</private-session-attributes>
- <render-weight>50</render-weight>
- <add-default-resource>true</add-default-resource>
- <system>true</system>
- </portlet>
这个portlet对应的页面在/html/portlet/layout_configuration/view.jsp中:
- <%@ include file="/html/portlet/layout_configuration/init.jsp" %>
- <c:if test="<%= themeDisplay.isSignedIn() && (layout != null) && (layout.isTypePortlet() || layout.isTypePanel()) %>">
- <%
- PortletURL refererURL = renderResponse.createActionURL();
- refererURL.setParameter("updateLayout", "true");
- %>
- <div id="portal_add_content">
- <div class="portal-add-content">
- <aui:form action='<%= themeDisplay.getPathMain() + "/portal/update_layout?p_l_id=" + plid + "&p_v_l_s_g_id=" + themeDisplay.getParentGroupId() %>' method="post" name="fm" useNamespace="<%= false %>">
- <aui:input name="doAsUserId" type="hidden" value="<%= themeDisplay.getDoAsUserId() %>" />
- <aui:input name="<%= Constants.CMD %>" type="hidden" value="template" />
- <aui:input name="<%= WebKeys.REFERER %>" type="hidden" value="<%= refererURL.toString() %>" />
- <aui:input name="refresh" type="hidden" value="<%= true %>" />
- <c:if test="<%= layout.isTypePortlet() %>">
- <div class="portal-add-content-search">
- <span id="portal_add_content_title"><liferay-ui:message key="search-applications-searches-as-you-type" /></span>
- <aui:input cssClass="lfr-auto-focus" id="layout_configuration_content" label="" name="layout_configuration_content" onKeyPress="if (event.keyCode == 13) { return false; }" />
- </div>
- </c:if>
- <%
- UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();
- Set panelSelectedPortlets = SetUtil.fromArray(StringUtil.split(typeSettingsProperties.getProperty("panelSelectedPortlets")));
- PortletCategory portletCategory = (PortletCategory)WebAppPool.get(company.getCompanyId(), WebKeys.PORTLET_CATEGORY);
- portletCategory = _getRelevantPortletCategory(permissionChecker, portletCategory, panelSelectedPortlets, layoutTypePortlet, layout, user);
- List categories = ListUtil.fromCollection(portletCategory.getCategories());
- categories = ListUtil.sort(categories, new PortletCategoryComparator(locale));
- int portletCategoryIndex = 0;
- Iterator itr = categories.iterator();
- while (itr.hasNext()) {
- PortletCategory curPortletCategory = (PortletCategory)itr.next();
- if (curPortletCategory.isHidden()) {
- continue;
- }
- request.setAttribute(WebKeys.PORTLET_CATEGORY, curPortletCategory);
- request.setAttribute(WebKeys.PORTLET_CATEGORY_INDEX, String.valueOf(portletCategoryIndex));
- %>
- <liferay-util:include page="/html/portlet/layout_configuration/view_category.jsp" />
- <%
- portletCategoryIndex++;
- }
- %>
- <c:if test="<%= layout.isTypePortlet() %>">
- <div class="portlet-msg-info">
- <liferay-ui:message key="to-add-a-portlet-to-the-page-just-drag-it" />
- </div>
- </c:if>
- <c:if test="<%= !layout.isTypePanel() && permissionChecker.isOmniadmin() %>">
- <%
- Group controlPanelGroup = GroupLocalServiceUtil.getGroup(company.getCompanyId(), GroupConstants.CONTROL_PANEL);
- long controlPanelPlid = LayoutLocalServiceUtil.getDefaultPlid(controlPanelGroup.getGroupId(), true);
- PortletURLImpl pluginsURL = new PortletURLImpl(request, PortletKeys.PLUGIN_INSTALLER, controlPanelPlid, PortletRequest.RENDER_PHASE);
- pluginsURL.setPortletMode(PortletMode.VIEW);
- pluginsURL.setRefererPlid(plid);
- %>
- <p class="lfr-install-more">
- <aui:a href="<%= pluginsURL.toString() %>" label="install-more-applications" />
- </p>
- </c:if>
- </aui:form>
- </div>
- </div>
- </c:if>
- <c:if test="<%= !themeDisplay.isSignedIn() %>">
- <liferay-ui:message key="please-sign-in-to-continue" />
- </c:if>
而这里面所有portlet以及分类都是用循环所包含进来的,见第55行:
所以每个Portlet分类以及其中的portlet都在/html/portlet/layout_configuration/view_category.jsp中:
- <%@ include file="/html/portlet/layout_configuration/init.jsp" %>
- ...
- <div class="lfr-add-content <%= layout.isTypePortlet() ? "collapsed" : "" %>" id="<portlet:namespace />portletCategory<%= portletCategoryIndex %>">
- <h2>
- <span><%= Validator.isNotNull(externalPortletCategory) ? externalPortletCategory : LanguageUtil.get(pageContext, portletCategory.getName()) %></span>
- </h2>
- <div class="lfr-content-category <%= layout.isTypePortlet() ? "aui-helper-hidden" : "" %>">
- ...
- <c:choose>
- <c:when test="<%= layout.isTypePortlet() %>">
- <div
- class="lfr-portlet-item <c:if test="<%= portletLocked %>">lfr-portlet-used</c:if> <c:if test="<%= portletInstanceable %>">lfr-instanceable</c:if>"
- id="<portlet:namespace />portletItem<%= portlet.getPortletId() %>"
- instanceable="<%= portletInstanceable %>"
- plid="<%= plid %>"
- portletId="<%= portlet.getPortletId() %>"
- title="<%= PortalUtil.getPortletTitle(portlet, application, locale) %>"
- >
- <p><%= PortalUtil.getPortletTitle(portlet, application, locale) %> <a href="javascript:;"><liferay-ui:message key="add" /></a></p>
- </div>
- <input id="<portlet:namespace />portletItem<%= portlet.getPortletId() %>CategoryPath" type="hidden" value="<%= divId.toString().replace(':', '-') %>" />
- ...
- <div
- class="lfr-portlet-item lfr-archived-setup"
- id="<portlet:namespace />portletItem<%= portletItem.getPortletItemId() %>"
- instanceable="<%= portletInstanceable %>"
- plid="<%= plid %>"
- portletId="<%= portlet.getPortletId() %>"
- portletItemId="<%= portletItem.getPortletItemId() %>"
- title="<%= HtmlUtil.escape(portletItem.getName()) %>"
- >
- <p><%= HtmlUtil.escape(portletItem.getName()) %> <a href="javascript:;"><liferay-ui:message key="add" /></a></p>
- </div>
- <input id="<portlet:namespace />portletItem<%= portletItem.getPortletItemId() %>CategoryPath" type="hidden" value="<%= divId.toString().replace(':', '-') %>" />
- <%
- }
- %>
- </c:when>
- <c:otherwise>
- <div>
- <a href="<liferay-portlet:renderURL portletName="<%= portlet.getRootPortletId() %>" windowState="<%= WindowState.MAXIMIZED.toString() %>"></liferay-portlet:renderURL>"><%= PortalUtil.getPortletTitle(portlet, application, locale) %></a>
- </div>
- </c:otherwise>
- </c:choose>
- <%
- }
- %>
- </div>
- </div>
- <input id="<portlet:namespace />portletCategory<%= portletCategoryIndex %>CategoryPath" type="hidden" value="<%= newCategoryPath.replace(':', '-') %>" />
- <%
- }
- %>
从这里很容易看出,每个分类对应的代码段是第6行开始,它的id为id="<portlet:namespace />portletCategory<%= portletCategoryIndex %>,而每个portlet的对应的代码段是从第17行开始,它对应的id为id="<portlet:namespace />portletItem<%= portlet.getPortletId() %>
我们来验证下:比如我们为了如下的显示:
对应的,因为layout_configuration对应的portletId为87(上文已说),对应的<portlet:namespace>为_87_。这个分类是第9个分类,而这个分类中包含的2个Portlet对应的id分别为34,67,见liferay-display.xml:
- ..
- <category name="category.shopping">
- <portlet id="34" />
- <portlet id="67" />
- </category>
- ..
所以,分类的id为_87_portletCategory9,而两个portlet的id分别为_87_portletItem67和_87_portletItem34,对比页面源码,果然这样: