Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
Torsten Kunze
Access request parameters in velocity template
March 4, 2008 1:18 AM
Answer

Torsten Kunze

Rank: New Member

Posts: 2

Join Date: March 4, 2008

Recent Posts

Hi,

I would like to access an own request parameter in my portal_normal.vm

I found this example:
http://wiki.liferay.com/index.php/Journal_Internal_API#Example_Velocity_Template

But unfortunately it does not work for me.
My request URL looks like this:
http://localhost:8888/web/guest/4?someid=1234

So I tried to access 'someid' via:
#set ($id = $request.get('someid'))
or
#set ($id = $request.get('parameters').get('someid'))
But nothing was set.

So I printed out:
$request
$request.get('parameters')

The first returns the object, the second doesn't.


What am I doing wrong?

Thanks in advance.
Best regards,
Torsten
Brandon Wagner
RE: Access request parameters in velocity template
December 12, 2008 12:39 PM
Answer

Brandon Wagner

Rank: Junior Member

Posts: 67

Join Date: May 14, 2008

Recent Posts

Old thread, but it's unanswered and I'm having the same problem. I tried the example exactly as its written and there is nothing in the request variable after submission. I can see my value in the querystring, but it is not being picked up with this code:

1  #set ($paramName = $request.get('parameters').get('name'))


I also tried just writing out the $request variable, and the "parameters" collection is empty. I only see my submitted form value in the CURRENT_URL parameter (tacked on to the end of the querystring).

Has anything changed since this Wiki was written (which looks to be the 4.3.5 release, so I'm guessing yes)? If so, can anyone give any guidance to any existing forum/blog posts or other docs. Or just pointers?

I'm trying to accomplish having two Journal portlets on one page, with links in one determining what article is displayed in the other, and I think this is the right way to go.

Any help is appreciated!

Thanks,

Brandon
Mike Kalohr
RE: Access request parameters in velocity template
January 9, 2009 7:50 AM
Answer

Mike Kalohr

Rank: New Member

Posts: 14

Join Date: August 28, 2007

Recent Posts

I have also tried a number of ways such as

- traditional php : echo $_GET['parameter"], tried to print the GLOBAL vars, etc.. It does not seem to work
- by using the java objects: $request->getParameter('test").. Id does not seem to work

I think that these approaches do not work because the php portlet is not designed to work that way.. is there another mechanism?
anybody?

cheers,

kalohr
Jeffrey Handa
RE: Access request parameters in velocity template
January 20, 2009 6:14 PM
Answer

Jeffrey Handa

LIFERAY STAFF

Rank: Liferay Master

Posts: 501

Join Date: December 1, 2008

Recent Posts

When creating the Journal Template, be sure to uncheck the cacheable check box. This will allow you to retrieve request parameters at follows:

#set($readmore = $request.get("parameters").get("read_more"))
Attachment

Attachments: cacheable.png (9.5k)
Fou crazy
RE: Access request parameters in velocity template
August 24, 2011 2:28 AM
Answer

Fou crazy

Rank: New Member

Posts: 15

Join Date: September 30, 2010

Recent Posts

Jeffrey Handa:
When creating the Journal Template, be sure to uncheck the cacheable check box. This will allow you to retrieve request parameters at follows:

#set($readmore = $request.get("parameters").get("read_more"))



Thanks! it works ok.
Mónica Rubio
RE: Access request parameters in velocity template
July 26, 2010 5:05 AM
Answer

Mónica Rubio

Rank: New Member

Posts: 6

Join Date: July 21, 2010

Recent Posts

Hi Brandon!

Did you solve this problem? I have exactly de same problem. For sometime it was working fine for me: '$request.get('parameters') returned a map of the parameters in the request, but suddenly it crashed. i haven't any configuration property in any configuration file.

Although it's long time since this thread started i hope you or somebody answer me, please. I'm going crazy.

Thanks
delang j
RE: Access request parameters in velocity template
February 15, 2009 3:43 AM
Answer

delang j

Rank: Regular Member

Posts: 240

Join Date: July 13, 2008

Recent Posts

hi
see here
http://www.liferay.com/web/guest/community/forums/-/message_boards/message/1051600
Mónica Rubio
RE: Access request parameters in velocity template
July 26, 2010 5:08 AM
Answer

Mónica Rubio

Rank: New Member

Posts: 6

Join Date: July 21, 2010

Recent Posts

I forgotten it. i have the 'cacheable' property unchecked.
Achmed Tyrannus Albab
RE: Access request parameters in velocity template
July 2, 2012 3:38 AM
Answer

Achmed Tyrannus Albab

Rank: Regular Member

Posts: 118

Join Date: March 5, 2010

Recent Posts

Hi,

Did you manage to do this via portal_normal.vm ?
If yes kindly share?

Regards,
Achmed Achmed

Torsten Kunze:
Hi,

I would like to access an own request parameter in my portal_normal.vm

I found this example:
http://wiki.liferay.com/index.php/Journal_Internal_API#Example_Velocity_Template

But unfortunately it does not work for me.
My request URL looks like this:
http://localhost:8888/web/guest/4?someid=1234

So I tried to access 'someid' via:
#set ($id = $request.get('someid'))
or
#set ($id = $request.get('parameters').get('someid'))
But nothing was set.

So I printed out:
$request
$request.get('parameters')

The first returns the object, the second doesn't.


What am I doing wrong?

Thanks in advance.
Best regards,
Torsten
Tejas Kanani
RE: Access request parameters in velocity template
July 2, 2012 4:07 AM
Answer

Tejas Kanani

Rank: Liferay Master

Posts: 655

Join Date: January 6, 2009

Recent Posts

Try this,

1
2#set ($current_url = $request.get("attributes").CURRENT_COMPLETE_URL)
3#set ($paramName='categoryId')
4#set ($categoryId = $httpUtil.getParameter($current_url, $paramName))


Where 'categoryId' is the parameter you want from url.
http://localhost:8080/web/guest/home?categoryId=10014
Magnus Indregard
RE: Access request parameters in velocity template
October 7, 2014 7:10 AM
Answer

Magnus Indregard

Rank: New Member

Posts: 1

Join Date: January 24, 2013

Recent Posts

Bringing this old thread to life again.

I've tried 2 of the suggested methods below, and they both work partially, but none of them work completely.

A:
#set ($paramName = $request.get('parameters').get('name'))

Not sure what happens with this one. It works in edit mode, when I append the parameter to the end of all the edit mode parameters:
somesite.com/somepage?p_p_id=56_INSTANCE_7UIk&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-4&p_p_col_pos=1&p_p_col_count=3&name=something

However, it does not work if it is the only parameter, or in combination with other random parameters. Doesn't make sense.

B:
#set ($current_url = $request.get("attributes").CURRENT_COMPLETE_URL)
#set ($paramName='name')
#set ($categoryId = $httpUtil.getParameter($current_url, $paramName))

This works beautifully, but only if "name" is the only parameter in the URL. If there are other parameters, it will fail.

Any suggestions to how I can make either solution work all the time is welcome and appreciated :-)

Thanks,
Magnus