【问题标题】:how to access liferay menu from portlet如何从 portlet 访问 liferay 菜单
【发布时间】:2013-02-19 06:42:45
【问题描述】:
  • 我在 navigation.vm 文件中定义了一个菜单,该菜单在 liferay 项目中运行良好。
  • 但我想从我的 portlet 访问这个菜单。
  • 有什么方法可以从portlet 入口点或view.jsp 访问菜单????

【问题讨论】:

    标签: gwt liferay portlet liferay-6


    【解决方案1】:

    导入liferay-ui标签库:

    <%@ 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 上的正常行为,您可以使用不同的属性来获得其他行为。

    【讨论】:

      【解决方案2】:

      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>
      

      【讨论】:

      • 我得到了所有的菜单和子菜单,但是我是如何得到图标的。喜欢:navClind.icon();
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-19
      • 1970-01-01
      • 2013-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多