在Liferay中获取布局友好的URL

时间:2013-11-14 00:45:02

标签: java liferay-6

我想基于布局ID获得布局的友好URL。例如,/ web / group / page。目前我就是这样做的:

Layout layout = LayoutLocalServiceUtil.getLayout(groupId, false, layoutId);

String groupFriendlyUrl = GroupLocalServiceUtil.getGroup(groupId).getFriendlyURL(); //will output /group
String layoutFriendlyUrl = layout.getFriendlyURL(); //will output /page
String webFriendlyUrl = String.format("/web%s%s", groupFriendlyUrl, layoutFriendlyUrl); //will output /web/group/page

我想知道是否有更好的方法可以使用一种方法完成此路径/ web / group / page。

2 个答案:

答案 0 :(得分:4)

如果您有plid(页面布局ID),请使用下面的getLayoutFriendlyURL()

Layout selectedLayout = LayoutLocalServiceUtil.getLayout(plid);
String url = PortalUtil.getLayoutFriendlyURL(selectedLayout, themeDisplay);

答案 1 :(得分:0)

  1. #wrap{ margin:0px auto; padding:0px; width:1100px; height: 106px; text-align: center; } ul.gallery{ list-style: none; margin: 0; padding: 0; } .gallery li { height: 100px; display: inline-block; margin-right: 6px; margin-bottom: 6px; width: 100px; } .gallery li:last-child { margin-right: 0; } .gallery li a { height: 100px; width: 100px; } .gallery li a img { max-width: 100px; }

  2. ThemeDisplay theme = (ThemeDisplay) getPortletRequest().getAttribute(WebKeys.THEME_DISPLAY);

  3. final long GROUP_ID = theme.getLayout().getGroupId(); Layout destinationLayout = LayoutLocalServiceUtil.getFriendlyURLLayout(GROUP_ID, false, friendlyUrl);