Liferay diaries: Directing between different portlets on different pages

In my latest project I’ve came across the following UI construct:

A portlet with a search form displays results. When the user clicks on one of the result entries, a detail view should be shown which however resides in a different portlet… on a different page.
Surprisingly, the solution revolves around craftly constructing the right URL which can break out of the current page and also targets the correct portlet.

<liferay-portlet:actionURL var="searchUrl" portletMode="view" name="findInvoices" portletName="TargetPortlet_WAR_ApplicationName">
    <liferay-portlet:param name="invoiceId" value="${invoice.invoiceId}"></liferay-portlet:param>
    <liferay-portlet:param name="sequence" value="${invoice.sequence}"></liferay-portlet:param>
    <liferay-portlet:param name="date">
        <jsp:attribute name="value" trim="true">
        <acs:date value="${}"/></jsp:attribute>


<a href="<%=searchUrl.replaceAll("/current-page","/other-page") %>">click</a>

A quick dissection of the elements in this example:
The source portlet resides on a page under the /current-page URL (i.e. http://localhost:8080/current-page?....) and wants to direct to a different portlet (TargetPortlet) on a different page (/other-page) by invoking the findInvoices action.
liferay-portlet:actionURL constructs URLs that direct to any action of any portlet on the same page the current portlet is running on, also accepting any number of URL parameters. This leaves us with a final task, namely setting the correct page for the computed URL which we’re doing with an (admittedly) uggly string replacement in a scriptlet.

A final word about TargetPortlet_WAR_ApplicationName: apparently this is a convention Liferay uses for constructing not only portlet names, but also parameters destined at that portlet and you should be able to deduct it by observing the URL formation of existing portlets in your project.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.