Dims
Dims

Reputation: 50999

How to get Layout instance's URL in Liferay? What is friendly URL base?

Suppose I have Layout instance (in Java or JSP) and I want to get it's URL.

Layout represents a page. Page has "friendly URL" and I can get it by friendlyURL property.

But what about FULL url?

I can also get scopeGroup's friendly url, where

Group scopeGroup = themeDisplay.getScopeGroup();

and obtain more short part, which is also not full.

Company.getPortalURL

also does not contain all other text (does not include port and "/web" parts).

Inside \ROOT\html\portlet\layouts_admin\layout\details.jsp I found the following code to build it

    boolean privateLayout = ((Boolean)renderRequest.getAttribute("edit_pages.jsp-privateLayout")).booleanValue();
    Layout selLayout = (Layout)renderRequest.getAttribute("edit_pages.jsp-selLayout");

    StringBuilder friendlyURLBase = new StringBuilder();
    friendlyURLBase.append(themeDisplay.getPortalURL());


    LayoutSet layoutSet = selLayout.getLayoutSet();

    String virtualHostname = layoutSet.getVirtualHostname();

    if (Validator.isNull(virtualHostname) || (friendlyURLBase.indexOf(virtualHostname) == -1)) {
        friendlyURLBase.append(scopeGroup.getPathFriendlyURL(privateLayout, themeDisplay));
        friendlyURLBase.append(scopeGroup.getFriendlyURL());
    }

but this code is based on strange parameters edit_pages.jsp-privateLayout and edit_pages.jsp-selLayout which I am afraid will not be accessible in normal portlet.

So, how to obtain FULL URL of page instance?

Upvotes: 0

Views: 4903

Answers (1)

Andrea Di Giorgi
Andrea Di Giorgi

Reputation: 967

Try this:

PortalUtil.getLayoutFullURL(layout, themeDisplay)

Upvotes: 3

Related Questions