需求:

我们公司需要从breadcrumb上去掉最前面的那个Liferay,如图:

我们想只保留"Welcome",而去掉前面的"Liferay"

 

问题分析:

为了解决这个需求,我们首先要找到这个Welcome是怎么出现的,它定义在breadcrumb.jsp中:

   
   
   
   
  1. <liferay-ui:breadcrumb showCurrentGroup="<%= false %>" showCurrentPortlet="<%= false %>" showGuestGroup="<%= false %>" showLayout="<%= false %>" showParentGroups="<%= false %>" /> 

我们找到这个的定义,它在liferay-ui.tld文件中:

   
   
   
   
  1. <tag> 
  2.         <name>breadcrumbname> 
  3.         <tag-class>com.liferay.taglib.ui.BreadcrumbTagtag-class> 
  4.         <body-content>JSPbody-content> 
  5.         <attribute> 
  6.             <name>displayStylename> 
  7.             <required>falserequired> 
  8.             <rtexprvalue>truertexprvalue> 
  9.         attribute> 
  10.         <attribute> 
  11.             <name>portletURLname> 
  12.             <required>falserequired> 
  13.             <rtexprvalue>truertexprvalue> 
  14.         attribute> 
  15.         <attribute> 
  16.             <name>selLayoutname> 
  17.             <required>falserequired> 
  18.             <rtexprvalue>truertexprvalue> 
  19.         attribute> 
  20.         <attribute> 
  21.             <name>selLayoutParamname> 
  22.             <required>falserequired> 
  23.             <rtexprvalue>truertexprvalue> 
  24.         attribute> 
  25.         <attribute> 
  26.             <name>showCurrentGroupname> 
  27.             <required>falserequired> 
  28.             <rtexprvalue>truertexprvalue> 
  29.         attribute> 
  30.         <attribute> 
  31.             <name>showCurrentPortletname> 
  32.             <required>falserequired> 
  33.             <rtexprvalue>truertexprvalue> 
  34.         attribute> 
  35.         <attribute> 
  36.             <name>showGuestGroupname> 
  37.             <required>falserequired> 
  38.             <rtexprvalue>truertexprvalue> 
  39.         attribute> 
  40.         <attribute> 
  41.             <name>showLayoutname> 
  42.             <required>falserequired> 
  43.             <rtexprvalue>truertexprvalue> 
  44.         attribute> 
  45.         <attribute> 
  46.             <name>showParentGroupsname> 
  47.             <required>falserequired> 
  48.             <rtexprvalue>truertexprvalue> 
  49.         attribute> 
  50.         <attribute> 
  51.             <name>showPortletBreadcrumbname> 
  52.             <required>falserequired> 
  53.             <rtexprvalue>truertexprvalue> 
  54.         attribute> 
  55.     tag> 

所以它的实现在BreadcrumbTag类中,我们跟进到BreadcrumbTag类中,可以发现,真正用来显示的内容的页面在page.jsp中:

   
   
   
   
  1. private static final String _PAGE = "/html/taglib/ui/breadcrumb/page.jsp"

我们在page.jsp中看到,它先判断layout是否不为null(默认是不为null)的,所以它会去引入display_style_XX.jsp

   
   
   
   
  1. <c:if test="<%= layout != null %>"> 
  2.     <liferay-util:include page='<%= "/html/taglib/ui/breadcrumb/display_style_" + displayStyle + ".jsp" %>' /> 
  3. c:if> 

这个XX就是水平或者竖直,对应的XX=horizontal或者vertical.

因为我们例子中这个显示方式是水平的,所以我们最终找到了这个页面,是display_style_horizontal.jsp:

   
   
   
   
  1. <
  2. StringBundler sb = new StringBundler(); 
  3.  
  4. if (showGuestGroup) { 
  5.     _buildGuestGroupBreadcrumb(themeDisplay, sb); 
  6.  
  7. if (showParentGroups) { 
  8.     _buildParentGroupsBreadcrumb(selLayout.getLayoutSet(), portletURL, themeDisplay, sb); 
  9.  
  10. if (showLayout) { 
  11.     _buildLayoutBreadcrumb(selLayout, selLayoutParam, true, portletURL, themeDisplay, sb); 
  12.  
  13. if (showPortletBreadcrumb) { 
  14.     _buildPortletBreadcrumb(request, showCurrentGroup, showCurrentPortlet, themeDisplay, sb); 
  15.  
  16. String breadcrumbString = sb.toString(); 
  17.  
  18. if (Validator.isNotNull(breadcrumbString)) { 
  19.     int pos = breadcrumbString.indexOf("<li"); 
  20.  
  21.     breadcrumbString = StringUtil.insert(breadcrumbString, " class=\"first\"", pos + 3); 
  22.  
  23.     pos = breadcrumbString.lastIndexOf("<li"); 
  24.  
  25.     breadcrumbString = StringUtil.insert(breadcrumbString, " class=\"last\"", pos + 3); 
  26. %> 
  27.  
  28. <ul class="breadcrumbs breadcrumbs-horizontal lfr-component"> 
  29.     <%= breadcrumbString %> 
  30. ul> 

所以最终显示的导航条是由字符串拼接而成的(breadcrumbString),这样我们就很容易找到了这个"Liferay"的显示是最左边一个,也就是showGuestGroup,见04-06行。所以我们只需要吧showGuestGroup设置为false就达到目的了。

 

解决方法:

我们只要吧showGuestGroup设置为false,为此在portal-ext.properties中加入一行:

   
   
   
   
  1. #added by charles to fix the navigation issue ,remove "Liferay" 
  2. breadcrumb.show.guest.group=false  

就大功告成了。