Cookies help us deliver our services.

By using our services, you agree to our use of cookies. Learn more

I understand

In a previous article (How to create PortletURL with Javascript) I explained how to create a PortletURL using the Liferay JavaScript library.

As explained by that time it works perfectly except than in the case Liferay is installed outside the ROOT context of Tomcat; so let's see how.

The problem is that Javascript library generates the URL as if Liferay was installed inside the Tomcat ROOT context and so the final generated address is wrong.

Unfortunately, the only solution is to build the base path of each URL, then use it to build the complete URL:

<aui:script use="liferay-portlet-url">
var basePortletURL = Liferay.ThemeDisplay.getPathMain() + '/portal/layout?p_l_id=' + Liferay.ThemeDisplay.getPlid();
var url = new Liferay.PortletURL(Liferay.PortletURL.RENDER_PHASE, null, basePortletURL);

The sign of the constructor is the following:

var PortletURL = function(lifecycle, params, basePortletURL) { ... }


  • lifecycle, is the URL type to create and it can be:
    • Liferay.PortletURL.ACTION_PHASE
    • Liferay.PortletURL.RENDER_PHASE
    • Liferay.PortletURL.RESOURCE_PHASE
  • params, are the URL parameters
  • basePortletURL, is the base portlet URL

Let's add that the function call we used in the past article:

var portletURL = Liferay.PortletURL.createRenderURL();

is the same as:

var portletURL = new Liferay.PortletURL(Liferay.PortletURL.RENDER_PHASE);

So you can then use what we have seen previously.