需求:
我们公司需要从breadcrumb上去掉最前面的那个Liferay,如图:
我们想只保留"Welcome",而去掉前面的"Liferay"
问题分析:
为了解决这个需求,我们首先要找到这个Welcome是怎么出现的,它定义在breadcrumb.jsp中:
- <liferay-ui:breadcrumb showCurrentGroup="<%= false %>" showCurrentPortlet="<%= false %>" showGuestGroup="<%= false %>" showLayout="<%= false %>" showParentGroups="<%= false %>" />
我们找到这个<liferay-ui:breadcrumb>的定义,它在liferay-ui.tld文件中:
- <tag>
- <name>breadcrumb</name>
- <tag-class>com.liferay.taglib.ui.BreadcrumbTag</tag-class>
- <body-content>JSP</body-content>
- <attribute>
- <name>displayStyle</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>portletURL</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>selLayout</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>selLayoutParam</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>showCurrentGroup</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>showCurrentPortlet</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>showGuestGroup</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>showLayout</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>showParentGroups</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- <attribute>
- <name>showPortletBreadcrumb</name>
- <required>false</required>
- <rtexprvalue>true</rtexprvalue>
- </attribute>
- </tag>
所以它的实现在BreadcrumbTag类中,我们跟进到BreadcrumbTag类中,可以发现,真正用来显示的内容的页面在page.jsp中:
- private static final String _PAGE = "/html/taglib/ui/breadcrumb/page.jsp";
我们在page.jsp中看到,它先判断layout是否不为null(默认是不为null)的,所以它会去引入display_style_XX.jsp
- <c:if test="<%= layout != null %>">
- <liferay-util:include page='<%= "/html/taglib/ui/breadcrumb/display_style_" + displayStyle + ".jsp" %>' />
- </c:if>
这个XX就是水平或者竖直,对应的XX=horizontal或者vertical.
因为我们例子中这个显示方式是水平的,所以我们最终找到了这个页面,是display_style_horizontal.jsp:
- <%
- StringBundler sb = new StringBundler();
- if (showGuestGroup) {
- _buildGuestGroupBreadcrumb(themeDisplay, sb);
- }
- if (showParentGroups) {
- _buildParentGroupsBreadcrumb(selLayout.getLayoutSet(), portletURL, themeDisplay, sb);
- }
- if (showLayout) {
- _buildLayoutBreadcrumb(selLayout, selLayoutParam, true, portletURL, themeDisplay, sb);
- }
- if (showPortletBreadcrumb) {
- _buildPortletBreadcrumb(request, showCurrentGroup, showCurrentPortlet, themeDisplay, sb);
- }
- String breadcrumbString = sb.toString();
- if (Validator.isNotNull(breadcrumbString)) {
- int pos = breadcrumbString.indexOf("<li");
- breadcrumbString = StringUtil.insert(breadcrumbString, " class=\"first\"", pos + 3);
- pos = breadcrumbString.lastIndexOf("<li");
- breadcrumbString = StringUtil.insert(breadcrumbString, " class=\"last\"", pos + 3);
- }
- %>
- <ul class="breadcrumbs breadcrumbs-horizontal lfr-component">
- <%= breadcrumbString %>
- </ul>
所以最终显示的导航条是由字符串拼接而成的(breadcrumbString),这样我们就很容易找到了这个"Liferay"的显示是最左边一个,也就是showGuestGroup,见04-06行。所以我们只需要吧showGuestGroup设置为false就达到目的了。
解决方法:
我们只要吧showGuestGroup设置为false,为此在portal-ext.properties中加入一行:
- #added by charles to fix the navigation issue ,remove "Liferay"
- breadcrumb.show.guest.group=false
就大功告成了。