Adding Friendly URL Mapping to the Portlet

When you click the Edit greeting link, you’re taken to a page with a URL that looks like this:


Since Liferay 6, there’s a built-in feature that can easily change the ugly URL above to this:


The feature is called friendly URL mapping. It takes unnecessary parameters out of the URL and allows you to place the important parameters in the URL path, rather than in the query string. To add this functionality, first edit liferay-portlet.xml and add the following lines directly after </icon> and before <instanceable> (remove the line breaks):


Next, create the file (remove the line break):


Place the following content into the new file (remove the line break after {mvcPathName}.jsp):

<?xml version="1.0"?>
<!DOCTYPE routes PUBLIC "-//Liferay//DTD Friendly URL Routes 6.1.0//EN" 

        <generated-parameter name="mvcPath">/{mvcPathName}.jsp\

Redeploy your portlet, refresh the page, and try clicking either of the links again.


Figure 3.9: Friendly URL for view JSP

Notice how much shorter and more user-friendly the URL is, without even having to modify the JSPs.


Figure 3.10: Friendly URL for edit JSP

For more information on friendly URL mapping, there’s a detailed discussion in Liferay in Action. Our next step here is to explore localization of the portlet’s user interface.

0 (0 Votes)
Developing a Portlet with Multiple Actions Previous