Liferay layout_configuration 分析

当在Dockbar上点击Add->More...后,就进入了layout_configuration:

 

这也是一个portlet(Liferay内核中的一个特殊的portlet),portlet_id为87,参见liferay-portlet.xml:

 
  
  1. <portlet> 
  2.         <portlet-name>87</portlet-name> 
  3.         <icon>/html/icons/default.png</icon> 
  4.         <struts-path>layout_configuration</struts-path> 
  5.         <use-default-template>false</use-default-template> 
  6.         <show-portlet-access-denied>false</show-portlet-access-denied> 
  7.         <show-portlet-inactive>false</show-portlet-inactive> 
  8.         <private-request-attributes>false</private-request-attributes> 
  9.         <private-session-attributes>false</private-session-attributes> 
  10.         <render-weight>50</render-weight> 
  11.         <add-default-resource>true</add-default-resource> 
  12.         <system>true</system> 
  13.     </portlet> 

 

这个portlet对应的页面在/html/portlet/layout_configuration/view.jsp中:

 
  
  1. <%@ include file="/html/portlet/layout_configuration/init.jsp" %> 
  2.  
  3. <c:if test="<%= themeDisplay.isSignedIn() && (layout != null) && (layout.isTypePortlet() || layout.isTypePanel()) %>"> 
  4.  
  5.     <
  6.     PortletURL refererURL = renderResponse.createActionURL(); 
  7.  
  8.     refererURL.setParameter("updateLayout", "true"); 
  9.     %> 
  10.  
  11.     <div id="portal_add_content"> 
  12.         <div class="portal-add-content"> 
  13.             <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 %>"> 
  14.                 <aui:input name="doAsUserId" type="hidden" value="<%= themeDisplay.getDoAsUserId() %>" /> 
  15.                 <aui:input name="<%= Constants.CMD %>" type="hidden" value="template" /> 
  16.                 <aui:input name="<%= WebKeys.REFERER %>" type="hidden" value="<%= refererURL.toString() %>" /> 
  17.                 <aui:input name="refresh" type="hidden" value="<%= true %>" /> 
  18.  
  19.                 <c:if test="<%= layout.isTypePortlet() %>"> 
  20.                     <div class="portal-add-content-search"> 
  21.                         <span id="portal_add_content_title"><liferay-ui:message key="search-applications-searches-as-you-type" /></span> 
  22.  
  23.                         <aui:input cssClass="lfr-auto-focus" id="layout_configuration_content" label="" name="layout_configuration_content" onKeyPress="if (event.keyCode == 13) { return false; }" /> 
  24.                     </div> 
  25.                 </c:if> 
  26.  
  27.                 <
  28.                 UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties(); 
  29.  
  30.                 Set panelSelectedPortlets = SetUtil.fromArray(StringUtil.split(typeSettingsProperties.getProperty("panelSelectedPortlets"))); 
  31.  
  32.                 PortletCategory portletCategory = (PortletCategory)WebAppPool.get(company.getCompanyId(), WebKeys.PORTLET_CATEGORY); 
  33.  
  34.                 portletCategory = _getRelevantPortletCategory(permissionChecker, portletCategory, panelSelectedPortlets, layoutTypePortlet, layout, user); 
  35.  
  36.                 List categories = ListUtil.fromCollection(portletCategory.getCategories()); 
  37.  
  38.                 categories = ListUtil.sort(categories, new PortletCategoryComparator(locale)); 
  39.  
  40.                 int portletCategoryIndex = 0
  41.  
  42.                 Iterator itr = categories.iterator(); 
  43.  
  44.                 while (itr.hasNext()) { 
  45.                     PortletCategory curPortletCategory = (PortletCategory)itr.next(); 
  46.  
  47.                     if (curPortletCategory.isHidden()) { 
  48.                         continue; 
  49.                     } 
  50.  
  51.                     request.setAttribute(WebKeys.PORTLET_CATEGORY, curPortletCategory); 
  52.                     request.setAttribute(WebKeys.PORTLET_CATEGORY_INDEX, String.valueOf(portletCategoryIndex)); 
  53.                 %> 
  54.  
  55.                     <liferay-util:include page="/html/portlet/layout_configuration/view_category.jsp" /> 
  56.  
  57.                 <
  58.                     portletCategoryIndex++; 
  59.                 } 
  60.                 %> 
  61.  
  62.                 <c:if test="<%= layout.isTypePortlet() %>"> 
  63.                     <div class="portlet-msg-info"> 
  64.                         <liferay-ui:message key="to-add-a-portlet-to-the-page-just-drag-it" /> 
  65.                     </div> 
  66.                 </c:if> 
  67.  
  68.                 <c:if test="<%= !layout.isTypePanel() && permissionChecker.isOmniadmin() %>"> 
  69.  
  70.                     <
  71.                     Group controlPanelGroup = GroupLocalServiceUtil.getGroup(company.getCompanyId(), GroupConstants.CONTROL_PANEL); 
  72.  
  73.                     long controlPanelPlid = LayoutLocalServiceUtil.getDefaultPlid(controlPanelGroup.getGroupId(), true); 
  74.  
  75.                     PortletURLImpl pluginsURL = new PortletURLImpl(request, PortletKeys.PLUGIN_INSTALLER, controlPanelPlid, PortletRequest.RENDER_PHASE); 
  76.  
  77.                     pluginsURL.setPortletMode(PortletMode.VIEW); 
  78.                     pluginsURL.setRefererPlid(plid); 
  79.                     %> 
  80.  
  81.                     <p class="lfr-install-more"> 
  82.                         <aui:a href="<%= pluginsURL.toString() %>" label="install-more-applications" /> 
  83.                     </p> 
  84.                 </c:if> 
  85.             </aui:form> 
  86.         </div> 
  87.     </div> 
  88. </c:if> 
  89.  
  90. <c:if test="<%= !themeDisplay.isSignedIn() %>"> 
  91.     <liferay-ui:message key="please-sign-in-to-continue" /> 
  92. </c:if> 

 

而这里面所有portlet以及分类都是用循环所包含进来的,见第55行:

所以每个Portlet分类以及其中的portlet都在/html/portlet/layout_configuration/view_category.jsp中:

 
  
  1. <%@ include file="/html/portlet/layout_configuration/init.jsp" %> 
  2.  
  3. ... 
  4.     <div class="lfr-add-content <%= layout.isTypePortlet() ? "collapsed" : "" %>" id="<portlet:namespace />portletCategory<%= portletCategoryIndex %>"> 
  5.         <h2> 
  6.             <span><%= Validator.isNotNull(externalPortletCategory) ? externalPortletCategory : LanguageUtil.get(pageContext, portletCategory.getName()) %></span> 
  7.         </h2> 
  8.  
  9.         <div class="lfr-content-category <%= layout.isTypePortlet() ? "aui-helper-hidden" : "" %>"> 
  10.  
  11.             ... 
  12.                 <c:choose> 
  13.                     <c:when test="<%= layout.isTypePortlet() %>"> 
  14.                         <div 
  15.                             class="lfr-portlet-item <c:if test="<%= portletLocked %>">lfr-portlet-used</c:if> <c:if test="<%= portletInstanceable %>">lfr-instanceable</c:if>
  16.                             id="<portlet:namespace />portletItem<%= portlet.getPortletId() %>" 
  17.                             instanceable="<%= portletInstanceable %>" 
  18.                             plid="<%= plid %>" 
  19.                             portletId="<%= portlet.getPortletId() %>" 
  20.                             title="<%= PortalUtil.getPortletTitle(portlet, application, locale) %>" 
  21.                         > 
  22.                             <p><%= PortalUtil.getPortletTitle(portlet, application, locale) %> <a href="javascript:;"><liferay-ui:message key="add" /></a></p> 
  23.                         </div> 
  24.  
  25.                         <input id="<portlet:namespace />portletItem<%= portlet.getPortletId() %>CategoryPath" type="hidden" value="<%= divId.toString().replace(':', '-') %>" /> 
  26.  
  27.                         ... 
  28.  
  29.                             <div 
  30.                                 class="lfr-portlet-item lfr-archived-setup" 
  31.                                 id="<portlet:namespace />portletItem<%= portletItem.getPortletItemId() %>" 
  32.                                 instanceable="<%= portletInstanceable %>" 
  33.                                 plid="<%= plid %>" 
  34.                                 portletId="<%= portlet.getPortletId() %>" 
  35.                                 portletItemId="<%= portletItem.getPortletItemId() %>" 
  36.                                 title="<%= HtmlUtil.escape(portletItem.getName()) %>" 
  37.                             > 
  38.                                 <p><%= HtmlUtil.escape(portletItem.getName()) %> <a href="javascript:;"><liferay-ui:message key="add" /></a></p> 
  39.                             </div> 
  40.  
  41.                             <input id="<portlet:namespace />portletItem<%= portletItem.getPortletItemId() %>CategoryPath" type="hidden" value="<%= divId.toString().replace(':', '-') %>" /> 
  42.  
  43.                         <
  44.                         } 
  45.                         %> 
  46.  
  47.                     </c:when> 
  48.                     <c:otherwise> 
  49.                         <div> 
  50.                             <a href="<liferay-portlet:renderURL portletName="<%= portlet.getRootPortletId() %>windowState="<%= WindowState.MAXIMIZED.toString() %>"></liferay-portlet:renderURL>"><%= PortalUtil.getPortletTitle(portlet, application, locale) %></a> 
  51.                         </div> 
  52.                     </c:otherwise> 
  53.                 </c:choose> 
  54.  
  55.             <
  56.             } 
  57.             %> 
  58.  
  59.         </div> 
  60.     </div> 
  61.  
  62.     <input id="<portlet:namespace />portletCategory<%= portletCategoryIndex %>CategoryPath" type="hidden" value="<%= newCategoryPath.replace(':', '-') %>" /> 
  63.  
  64. <
  65. %> 

从这里很容易看出,每个分类对应的代码段是第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:

 
  
  1. .. 
  2. <category name="category.shopping"> 
  3.         <portlet id="34" /> 
  4.         <portlet id="67" /> 
  5. </category> 
  6. .. 

所以,分类的id为_87_portletCategory9,而两个portlet的id分别为_87_portletItem67和_87_portletItem34,对比页面源码,果然这样:





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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值