2
votes

I have designed a webpage with a single portlet. I want to pass parameters to this portlet. So I am calling my webpage this way (on a local liferay instance): http://localhost:8080/group//?param=1

To avoid misunderstandings, I am not just trying to pass parameters between pages of a portlet (controller to view). I know how to do this and it works fine. In this case I am trying to start my portlet with parameters from the URL hosting it.

My understanding from the docs is that the portlet is not able to access the URL parameters The advised solution that I read about was to use "friendly-url-mapper".

I did not manage to get it to work. Here is what I did so far:

I added into liferay-portlet.xml:

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

Is view the correct value to set? Real doubt about it.

I created friendly-url-routes-for-parameters.xml with this content:

<routes>
    <route>
        <pattern>/result?{match}</pattern>
        <implicit-parameter name="param">{match}</implicit-parameter>
    </route>
</routes>

/result is mapped to a result.jsp page into my controller class (this part works):

I would expect that : http://localhost:8080/group//?param= and / or http://localhost:8080/group///-/view/?param= would redirect to my result.jsp with the ?param= parameter.

What did I not understand correctly?

1
The URL you are forming is not correct. It should be something like localhost:8080/group/pages/results?param=1, then you can get it using httpServletRequest in your portlet.Parkash Kumar

1 Answers

3
votes

Ok you can and you can't but basically you shouldn't, but I'm no one to tell you what you should and shouldn't do .

What you should do to get this parameter is get hold of the original servlet

HttpServletRequest httpReq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(req));

Then you can simply get the parameter you wish by using the getParameter method

String myParam = httpReq.getParameter("param");

Hope this helps