Skip to content

Instantly share code, notes, and snippets.

@michalbcz
Created September 13, 2012 08:23
Show Gist options
  • Save michalbcz/3712849 to your computer and use it in GitHub Desktop.
Save michalbcz/3712849 to your computer and use it in GitHub Desktop.
liferay - obtain url to page (page is where you place your portlets it's like igoogle and gadget relation)
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
//Layout layout = LayoutLocalServiceUtil.getFriendlyURLLayout(themeDisplay.getScopeGroupId(), false, "/page-name");
HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request);
httpRequest = PortalUtil.getOriginalServletRequest(httpRequest);
//Retrieve layout id of another portlet. Layout is synonym for Page. Will it crash if there are multiple pages??? TODO test it
String portletId = "portletId"; // portlet id is string and you will find this in liferay database scheme or maybe it have some logic, but i don't know what and if it's compatible between liferay versions
long plid = PortalUtil.getPlidFromPortletId(themeDisplay.getScopeGroupId(), portletId);
//generate the URL. You may use PortletRequest.ACTION_PHASE if you want to jump into ACTION phase.
PortletURL portletURL = PortletURLFactoryUtil.create(httpRequest, portletId, plid , PortletRequest.RENDER_PHASE);
// portletURL.setParameter(parem, value); // add custom parameters which you want to pass to callee
String url = portletURL.toString(); // here you have absolute url to particular page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment