掲示板

Access request parameters in velocity template

16年前 に Torsten Kunze によって更新されました。

Access request parameters in velocity template

New Member 投稿: 2 参加年月日: 08/03/04 最新の投稿
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
15年前 に Brandon Wagner によって更新されました。

RE: Access request parameters in velocity template

Junior Member 投稿: 67 参加年月日: 08/05/15 最新の投稿
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
15年前 に Mike Kalohr によって更新されました。

RE: Access request parameters in velocity template

New Member 投稿: 14 参加年月日: 07/08/28 最新の投稿
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
15年前 に Jeffrey Handa によって更新されました。

RE: Access request parameters in velocity template

Liferay Master 投稿: 541 参加年月日: 08/12/01 最新の投稿
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
12年前 に Fou Crazy によって更新されました。

RE: Access request parameters in velocity template

New Member 投稿: 15 参加年月日: 10/09/30 最新の投稿
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.
13年前 に Mónica Rubio によって更新されました。

RE: Access request parameters in velocity template

New Member 投稿: 6 参加年月日: 10/07/21 最新の投稿
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
15年前 に delang j によって更新されました。

RE: Access request parameters in velocity template

Expert 投稿: 252 参加年月日: 08/07/14 最新の投稿
hi
see here
http://www.liferay.com/web/guest/community/forums/-/message_boards/message/1051600
13年前 に Mónica Rubio によって更新されました。

RE: Access request parameters in velocity template

New Member 投稿: 6 参加年月日: 10/07/21 最新の投稿
I forgotten it. i have the 'cacheable' property unchecked.
thumbnail
11年前 に Achmed Tyrannus Albab によって更新されました。

RE: Access request parameters in velocity template

Regular Member 投稿: 158 参加年月日: 10/03/05 最新の投稿
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
11年前 に Tejas Kanani によって更新されました。

RE: Access request parameters in velocity template

Liferay Master 投稿: 654 参加年月日: 09/01/06 最新の投稿
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
9年前 に Magnus Indregard によって更新されました。

RE: Access request parameters in velocity template

New Member 投稿: 1 参加年月日: 13/01/24 最新の投稿
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