Forums de discussion

Access request parameters in velocity template

Torsten Kunze, modifié il y a 16 années.

Access request parameters in velocity template

New Member Publications: 2 Date d'inscription: 04/03/08 Publications récentes
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
thumbnail
Brandon Wagner, modifié il y a 15 années.

RE: Access request parameters in velocity template

Junior Member Publications: 67 Date d'inscription: 15/05/08 Publications récentes
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:

  #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
thumbnail
Mike Kalohr, modifié il y a 15 années.

RE: Access request parameters in velocity template

New Member Publications: 14 Date d'inscription: 28/08/07 Publications récentes
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
thumbnail
Jeffrey Handa, modifié il y a 15 années.

RE: Access request parameters in velocity template

Liferay Master Publications: 541 Date d'inscription: 01/12/08 Publications récentes
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"))
thumbnail
Fou Crazy, modifié il y a 12 années.

RE: Access request parameters in velocity template

New Member Publications: 15 Date d'inscription: 30/09/10 Publications récentes
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, modifié il y a 13 années.

RE: Access request parameters in velocity template

New Member Publications: 6 Date d'inscription: 21/07/10 Publications récentes
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
thumbnail
delang j, modifié il y a 15 années.

RE: Access request parameters in velocity template

Expert Publications: 252 Date d'inscription: 14/07/08 Publications récentes
hi
see here
http://www.liferay.com/web/guest/community/forums/-/message_boards/message/1051600
Mónica Rubio, modifié il y a 13 années.

RE: Access request parameters in velocity template

New Member Publications: 6 Date d'inscription: 21/07/10 Publications récentes
I forgotten it. i have the 'cacheable' property unchecked.
thumbnail
Achmed Tyrannus Albab, modifié il y a 11 années.

RE: Access request parameters in velocity template

Regular Member Publications: 158 Date d'inscription: 05/03/10 Publications récentes
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
thumbnail
Tejas Kanani, modifié il y a 11 années.

RE: Access request parameters in velocity template

Liferay Master Publications: 654 Date d'inscription: 06/01/09 Publications récentes
Try this,


#set ($current_url = $request.get("attributes").CURRENT_COMPLETE_URL)
#set ($paramName='categoryId')
#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, modifié il y a 9 années.

RE: Access request parameters in velocity template

New Member Envoyer: 1 Date d'inscription: 24/01/13 Publications récentes
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