Foren

Passing GET parameters to portlets

thumbnail
Tim Lewis, geändert vor 13 Jahren.

Passing GET parameters to portlets

New Member Beiträge: 17 Beitrittsdatum: 01.07.10 Neueste Beiträge
Hi All,
I have been pouring over the Web and Liferay, and cannot figure this out.

I have a page with a Web Content Display portlet on it, which contains a link to another page:

/player?movie="test.mp4"

I want to retrieve this parameter 'movie' on the 'player' page using its underlying velocity template. I will then insert this variable into the Flash code to make the video selected on the link appear in the player.

This seems as though it should be simple. Are my instincts wrong here?

Thanks,
Tim
thumbnail
Tina Agrawal, geändert vor 13 Jahren.

RE: Passing GET parameters to portlets

Expert Beiträge: 297 Beitrittsdatum: 03.01.08 Neueste Beiträge
I am not sure what you mean by using underlying velocity template.
But this is how you can get the movie parameter in your portlet class -



HttpServletRequest convertReq = PortalUtil.getHttpServletRequest(request);
HttpServletRequest originalReq = PortalUtil.getOriginalServletRequest(convertReq);
		
String movieName = originalReq.getParameter("movie");



Where request is of type RenderRequest.

Regards,
Tina
thumbnail
Tim Lewis, geändert vor 13 Jahren.

RE: Passing GET parameters to portlets

New Member Beiträge: 17 Beitrittsdatum: 01.07.10 Neueste Beiträge
Hi Tina,
I have a page called Videos, which has a Web Content Display portlet, which has a link with an href of '/player?movie=test.mp4'. I have a page called Player, which has a structure and VM template. I want to access the GET parameter 'movie' sent from the Videos page in this VM template.

Thanks,
Tim
thumbnail
Tim Lewis, geändert vor 13 Jahren.

RE: Passing GET parameters to portlets

New Member Beiträge: 17 Beitrittsdatum: 01.07.10 Neueste Beiträge
Anyone else able to comment? Liferay staff? I am not a portlet developer, so I need a way to send and receive HTTP parameters between Liferay pages. Use case is simple:

-- Page one has a link pointing to page two, sending it a parameter in the URL
-- Page two reads that parameter, and inserts it into the HTML for that page.

I am trying to do this using a Velocity template in page 2. Am I taking the wrong approach? Is the task harder than it looks?
thumbnail
Ricardo J. Vandelay, geändert vor 13 Jahren.

RE: Passing GET parameters to portlets

New Member Beiträge: 17 Beitrittsdatum: 24.02.10 Neueste Beiträge
Hi Tim.


#set($currentURL = "$getterUtil.getString($request.attributes.CURRENT_COMPLETE_URL)")
$httpUtil.getParameter($currentURL, "yourParameterNameHere")


Try it out.

You should check http://www.liferay.com/community/wiki/-/wiki/Main/CMS+Template+%28Velocity%29 for more info on the available velocity variables and also com.liferay.portal.velocity.VelocityVariables in the source code for more detail on the available methods on those variables.

Regards.
thumbnail
Tim Lewis, geändert vor 13 Jahren.

RE: Passing GET parameters to portlets

New Member Beiträge: 17 Beitrittsdatum: 01.07.10 Neueste Beiträge
Hi Ricardo,
I am grateful for your reply. Your solution worked for me. Before I read your post, I had retrieved CURRENT_COMPLETE_URL, but for the life of me, could not figure out a way to parse the URL for the parameters in the velocity template. Does the link you provided talk about $httpUtil? I don't remember seeing that variable listed for Velocity. I will review the material. I am finding it difficult to locate the info I need to keep going with this, so your help was vital.

I just dipped my toes into portal development earlier tonight; who knows, perhaps soon I will be creating portlets to solve these kinds of problems.

Along those lines, perhaps you could answer another question: I created a test portlet, and loaded it onto a page. I would like to pass it a GET parameter from another page, via a link. I tried simply typing into the URL bar something like /page2?video=test.mp4. I was unable to get the GET parameter to appear on page2. I am just not clear what Java method to call in the view.jsp to get it to show up. Is it simple, or is it a context/scope issue? My view.jsp contains something like this:


<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineobjects />

This is the <b>Test</b> portlet.
Request URI: &lt;%= request.getRequestURI() %&gt;
Hello <b>&lt;%= request.getParameter("video") %&gt;</b>! 




Thanks again, Ricardo. You made my evening!

Regards,
Tim
thumbnail
Ricardo J. Vandelay, geändert vor 13 Jahren.

RE: Passing GET parameters to portlets

New Member Beiträge: 17 Beitrittsdatum: 24.02.10 Neueste Beiträge
Hi Tim.

In that case it's a scope problem. You have two choices.

1. Your URL must be something like this:
http://yourdomain?p_p_id=THE_PORTLET_ID&_THE_PORTLET_ID_VARIABLENAME=value

2. Use Tina Agrawal's answer

Regards,
Ricardo
Nwawel Nwawel A Iroume, geändert vor 9 Jahren.

RE: Passing GET parameters to portlets

New Member Beiträge: 9 Beitrittsdatum: 28.09.14 Neueste Beiträge
It is about decades that i was looking for passing parameter between two portlet in different pages this work pretty fine!
thank agrawal emoticonemoticonemoticon
thumbnail
Domingo Piña, geändert vor 9 Jahren.

RE: Passing GET parameters to portlets

Junior Member Beiträge: 28 Beitrittsdatum: 03.04.09 Neueste Beiträge

    #set ( $convertReq = $portalUtil.getHttpServletRequest($renderRequest) )
    #set ( $originalReq = $portalUtil.getOriginalServletRequest($convertReq) )
    #set ( $catParam = $originalReq.getParameter("paramName") )