Search code examples
liferay-6

Liferay 6: Can the Liferay Friendly URL can be modified in my case


I am using liferay 6.1

I have added this inside the liferay-portet.xml file

<friendly-url-mapper-class>com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper</friendly-url-mapper-class>
<friendly-url-mapping>Gasd</friendly-url-mapping>
<friendly-url-routes>com/test/friendlier-friendly-url-routes.xml</friendly-url-routes>

And as per the COntext root (Or the Portlet name ) this is my friendlier-friendly-url-routes.xml

<routes>
<route>
    <pattern>/satportlet</pattern>
</route>
</routes>

But still the URL of that Portlet looks this way when i did a Submit Operation

http://localhost:8086/web/guest/home/-/Gasd/satportlet?p_auth=EFAy7VSA&p_p_lifecycle=1&_satportlet_WAR_SatPractportlet_javax.portlet.action=addBook

Is there anyway that this can be improved .

I am very much new to Liferay , please suggest me , i am ready to do chnages as you mention .


Solution

  • Yes it can be improved.

    For Example for a render URL in JSP, to view a User in the portlet:

    <portlet:renderURL windowState="maximized" var="myURL">
        <portlet:param name="resourcePrimKey" value="<%=user.getUserId() %>" />
        <portlet:param name="jspPage" value="/html/viewMyUser.jsp" />
    </portlet:renderURL>
    

    You can have the friendly URL route in your friendlier-friendly-url-routes.xml like this:

    <route>                                   
        <pattern>/satportlet/{resourcePrimKey:\d+}/view</pattern>  
        <!-- \d+ is the place-holder for the userID, i.e. 5 in the friendly URL below -->
        <implicit-parameter name="p_p_lifecycle">0</implicit-parameter>
        <!-- Implicit parameters are not shown in the route pattern, here 0,1 etc are the phases of the portlet 0=render, 1=action etc -->
        <implicit-parameter name="p_p_state">maximized</implicit-parameter>
        <implicit-parameter name="jspPage">/html/viewMyUser.jsp</implicit-parameter>
    </route>
    

    So the generated friendly URL would be:

    http://localhost:8086/web/guest/home/-/Gasd/satportlet/5/view
    

    In your case looking at your generated URL you can have the <route> element something like this (if the <portlet:actionURL> or <portlet:renderURL> you are using in the JSP was given I think it would be a little helpful to build the <route> element). I am not sure if this would be perfectly correct but it would be something like this:

    <route>
        <pattern>/satportlet/{p_auth}/{[p_p_id]_javax.portlet.action:\d+}</pattern>  
        <implicit-parameter name="p_p_lifecycle">1</implicit-parameter>
    </route>
    

    So I guess (again I am not sure enough) with the above configuration it should generate the friendly URL as:

    http://localhost:8086/web/guest/home/-/Gasd/satportlet/EFAy7VSA/addBook
    

    You can also check liferay's source code and the *-friendly-url-routes.xml files for a much better understanding.

    Hope this atleast gives you a clue as to how the friendly URLs work in liferay.