Featured post

Docker setup for Liferay 7 with MySQL

Monday, 9 April 2012

Unable to create friendly url mapping with javascript in Liferay

I've set up friendly URL routing for my Liferay portlet, and it's working fine when I generate URLs with the standard JSP tags like so:
<portlet:renderURL var="resetUrl">
    <portlet:param name="start" value="5" />
which, given my mapping, produces a lovely URL like:
But when I generate URLs using the JavaScript PortletURL module, I get the full unfriendly URL. For instance:
var filterUrl = Liferay.PortletURL.createRenderURL();
filterUrl.setPortletId("<%= portletDisplay.getId() %>");
filterUrl.setParameter("start", "5");
location.href = filterUrl;
will generate
So the question is: How can I generate friendly URLs from JavaScript?

Solution : Here is the Hack - Just give it a try
<portlet:renderURL var="resetUrl">
    <portlet:param name="start" value="changeStart" />
then write javascript and replace param values like this -
function createStart(copyNavigationPointURL) {
    var start = document.getElementById("navigationPointId").value;

    copyNavigationPointURL = copyNavigationPointURL.replace(/changeStart/i,start);
    submitForm(document.hrefFm, copyNavigationPointURL);
And you have your friendly url ....

Your are just done, Try & Enjoy the function.....:)