1
votes

I'm trying to get friendly URL mapping to work for a Spring MVC portlet inside Liferay 6.1 and fail.

My additions to the liferay-portlet-xml are according to the manual and blog examples available and as follows:

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

with the friendly-url-routes.xml being

<!DOCTYPE routes PUBLIC "-//Liferay//DTD Friendly URL Routes 6.1.0//EN"
          "http://www.liferay.com/dtd/liferay-friendly-url-routes_6_1_0.dtd">
<routes>
  <route>
    <pattern>/{match}</pattern>
    <generated-parameter name="foo">{match}</generated-parameter>
  </route>
</routes>

My Spring MVC controller goes like

@Controller
@RequestMapping("VIEW")
public class CarModelController {

  @ActionMapping
  public void action(@RequestParam("foo") final String testParam,
            final ActionRequest request, final ActionResponse response) {
    this.logger.info("default action");
    this.logger.info("testParam = {}", testParam);
  }

  @RenderMapping
  public String render(final RenderRequest request, final RenderResponse response) {
    this.logger.info("default render");
    return "index";
  }
}

If I call my portlet using /baseurl/-/search/bar only the render phase output occurs, the action method isn't called.

If I create a link to this page using

<portlet:actionURL var="lastStepUrl">
  <portlet:param name="foo" value="bar" />
</portlet:actionURL>

the URL Liferay generates looks like /baseurl/-/search/bar?p_auth=sometoken&p_p_lifecycle=1. It executes the action phase correctly and I'm also able to call that URL directly. It does, however, include the p_auth and p_p_lifecycle parameters that I want to get rid of.

Any suggestions are welcomed warmly.

1
I don't know Liferay, but I would start by seeing what is happening in the POST/GET that the portlet:actionUrl is generating as apposed to what happens when you call it directly using something like Chrome's dev tools or FireFox's FireBug. You could then use something curl, start with an exact copy of the request that works, then start removing things until it stops working. This would identify what is causing one request to trigger and another to not. Things to look for: HTTP Request Type (POST/GET/etc.), any headers being sent, any POST/GET vars being sent, etc.CodeChimp

1 Answers

2
votes

I don't know much about Friendly URL in Liferay. But I believe you can't completely remove p_p_lifecycle from url because.

this parameter tells Liferay which action to perform. This paramater has two values (0 or 1).

  • 0 tells Liferay to just render the portlet,

  • whereas 1 tells Liferay to call the process Action Method.

Lets say you want to remove from certain action URL then can do it like this

<pattern>"your URL pattern"</pattern>
<implicit-parameter name="p_p_lifecycle">1</implicit-parameter>
<implicit-parameter name="javax.portlet.action">"Your action"</implicit-parameter>

As we know 1 for action phase we can hard code and put it into routes.xml file.same way for any render URL we can put 0

To remove p_auth try putting below properties in portal-ext.properties file

portlet.add.default.resource.check.enabled=false
auth.token.check.enabled=false