Search code examples
hrefliferay-6portlet

Liferay and <portlet:renderURL> to a friendly URL


I have created a page with a friendly URL of /balance-inquiries. The full URL given within the Liferay Admin's Site Pages page is http://localhost:8080/group/guest/balance-inquiries.

Creating a renderUrl (or an actionUrl) to this page, from another page is proving to be a bit frustrating. Below is one of many variations I have tried to get this working.

<portlet:renderURL var="searchTransactionsUrl">
    <portlet:param name="mvcPath" value="/balance-inquiries" />
</portlet:renderURL>
<a href="<%=searchTransactionsUrl%>">Search LPC Transactions</a>

My question is what param values should I use to make this link work? Or should I resort to a redirect, or using instead?

Thanks in advance.


Solution

  • I've figured out how to build dynamic URLs for portlets spanning different WAR files. The code is as follows:

    <portlet:defineObjects />
    <liferay-theme:defineObjects />
    
    <%
        String portletId = "giftcardtransactionfilesummary_WAR_myportalgiftcardportlet";
        long otherPlid = PortalUtil.getPlidFromPortletId(themeDisplay.getScopeGroupId(), portletId);
    %>
    
    <liferay-portlet:renderURL var="giftcardTransactionFileSummaryUrl" plid="<%=otherPlid%>" portletName="<%=portletId%>">
        <liferay-portlet:param name="groupId" value="10157" />
        <liferay-portlet:param name="articleId" value="11385" />
    </liferay-portlet:renderURL>
    
    <a href="<%=giftcardTransactionFileSummaryUrl%>">view giftcard batch files</a>
    

    The tricks are as follows:

    • Understanding the naming convention behind Liferay-generated portletIds
    • Adding < liferay-theme:defineObjects /> to your page, as that injects a value for themeDisplay

    Other than that, adding the necessary @page and @taglib directives, and all should work.