4
- 我在navigation.vm文件中定义了一个在liferay项目中运行良好的菜单。
- 但我想从我的portlet访问此菜单。
- 有什么办法从portlet入口点或view.jsp访问菜单吗?
这个link描述了直接在jsp中获取菜单项的方法。
下面的代码是直接从一些改进格式上面的链接复制:
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.liferay.portal.model.Layout"%>
<%@ page import="com.liferay.portal.kernel.util.WebKeys"%>
<%@ page import="com.liferay.portal.theme.NavItem" %>
<%@ page import="com.liferay.portal.theme.RequestVars" %>
<%@ page import="com.liferay.portal.theme.ThemeDisplay"%>
<portlet:defineObjects />
<liferay-theme:defineObjects />
<div style="width:100%">
<%
//ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
String title = themeDisplay.getLayout().getName(themeDisplay.getLocale());
List<NavItem> navItems = new ArrayList<NavItem>();
if (layout != null) {
RequestVars requestVars = new RequestVars(request, themeDisplay, layout.getAncestorPlid(), layout.getAncestorLayoutId());
navItems = NavItem.fromLayouts(requestVars, layouts);
}
for (NavItem navItem : navItems) {
if (navItem.getName().equalsIgnoreCase(title)) {
if (navItem.hasChildren()) {
for(NavItem navChild : navItem.getChildren()) {
%>
<div style="float:left;" class="newsMenuPortlet">
<a href="<%= navChild.getURL() %>" <%=navChild.getTarget() %>>
<%= navChild.getName() %>
</a>
</div>
<%
} // inner for-loop ends here
}
}
}// outer for-loop ends here
%>
</div>
进口liferay-ui
的taglib:
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
那么你可以使用
<liferay-ui:navigation displayStyle="from-level-0" >
</liferay-ui:navigation>
注:设置displayStyle="from-level-0"
给你正常的行为就像navigation.vm
,你可以用属性不同的发挥得到其他行为。
感谢它也可以 – 2013-02-20 08:44:43
我得到了所有菜单和子菜单,但我怎么弄图标。像:navClind.icon(); – 2013-02-20 10:12:56