Foren

Access request parameters in velocity template

Torsten Kunze, geändert vor 16 Jahren.

Access request parameters in velocity template

New Member Beiträge: 2 Beitrittsdatum: 04.03.08 Neueste Beiträge
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, geändert vor 15 Jahren.

RE: Access request parameters in velocity template

Junior Member Beiträge: 67 Beitrittsdatum: 15.05.08 Neueste Beiträge
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, geändert vor 15 Jahren.

RE: Access request parameters in velocity template

New Member Beiträge: 14 Beitrittsdatum: 28.08.07 Neueste Beiträge
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, geändert vor 15 Jahren.

RE: Access request parameters in velocity template

Liferay Master Beiträge: 541 Beitrittsdatum: 01.12.08 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: Access request parameters in velocity template

New Member Beiträge: 15 Beitrittsdatum: 30.09.10 Neueste Beiträge
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, geändert vor 13 Jahren.

RE: Access request parameters in velocity template

New Member Beiträge: 6 Beitrittsdatum: 21.07.10 Neueste Beiträge
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, geändert vor 15 Jahren.

RE: Access request parameters in velocity template

Expert Beiträge: 252 Beitrittsdatum: 14.07.08 Neueste Beiträge
hi
see here
http://www.liferay.com/web/guest/community/forums/-/message_boards/message/1051600
Mónica Rubio, geändert vor 13 Jahren.

RE: Access request parameters in velocity template

New Member Beiträge: 6 Beitrittsdatum: 21.07.10 Neueste Beiträge
I forgotten it. i have the 'cacheable' property unchecked.
thumbnail
Achmed Tyrannus Albab, geändert vor 11 Jahren.

RE: Access request parameters in velocity template

Regular Member Beiträge: 158 Beitrittsdatum: 05.03.10 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: Access request parameters in velocity template

Liferay Master Beiträge: 654 Beitrittsdatum: 06.01.09 Neueste Beiträge
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, geändert vor 9 Jahren.

RE: Access request parameters in velocity template

New Member Beitrag: 1 Beitrittsdatum: 24.01.13 Neueste Beiträge
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