Java 在 Liferay 中获取布局友好的 URL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19967429/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 21:55:29  来源:igfitidea点击:

Get Layout Friendly URL In Liferay

javaliferay-6

提问by Rashidi Zin

I want to get a friendly URL for a layout based on layout id. For example, /web/group/page. Currently this is how I do it:

我想根据布局 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

I am wondering if there is a better way to do this where I can the full path, /web/group/page with one method.

我想知道是否有更好的方法来做到这一点,我可以使用一种方法获得完整路径 /web/group/page。

采纳答案by Khiem Tran

If you have plid(Page layout Id), use getLayoutFriendlyURL()like below:

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

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

回答by ACV

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

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

  3. Layout layout = LayoutLocalServiceUtil.getLayout(destinationLayout.getPlid()); String completeUrl = PortalUtil.getLayoutFullURL(layout, getThemeDisplay());

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

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

  3. Layout layout = LayoutLocalServiceUtil.getLayout(destinationLayout.getPlid()); String completeUrl = PortalUtil.getLayoutFullURL(layout, getThemeDisplay());