Forums de discussion

how to get request parameters in velocity template

thumbnail
Jerry Liu, modifié il y a 10 années.

how to get request parameters in velocity template

Junior Member Publications: 47 Date d'inscription: 29/10/13 Publications récentes
hi everybody!
as follows code
url:
localhost:8080/web/p01/tesat?n=23


#set($n = $request.getParameter('n'))
#set($n2 = $request.get('n'))
#set($n3 = $request.get("parameters").get("n"))
#set($n4 = $paramUtil.getLong($request,'n'))
#set($url = $request.attributes.CURRENT_URL)
#set($singleValue = $httpUtil.getParameter($url, 'n', false))
#set($n5 = $httpUtil.getParameterMap($httpUtil.getQueryString($url)).n)
#set ($current_url = $request.get("attributes").CURRENT_COMPLETE_URL)
#set ($paramName='n')
#set ($n6 = $httpUtil.getParameter($current_url, $paramName))


n:$n  <br>
n2:$n2  <br>
n3:$n3  <br>
n4:$n4  <br>
n5:$n5 <br>
n6:$n6 <br>



But nothing was set.
What am I doing wrong?
thanks.
thumbnail
meera prince, modifié il y a 10 années.

RE: how to get request parameters in velocity template

Liferay Legend Publications: 1111 Date d'inscription: 08/02/11 Publications récentes
thumbnail
Jerry Liu, modifié il y a 10 années.

RE: how to get request parameters in velocity template

Junior Member Publications: 47 Date d'inscription: 29/10/13 Publications récentes
meera prince:
Hi
You have covered all scenarios so one of should work..
Go through following links it mat help you..
http://stackoverflow.com/questions/8417505/velocity-vm-template-request-parameters-getting-get-variables

http://stackoverflow.com/questions/9531726/get-parameters-from-velocity-template

https://www.liferay.com/community/forums/-/message_boards/message/2304909

Regards,
Meera Prince


thanks Meera.
I've seen these,but there is no success.
thumbnail
Tejas Kanani, modifié il y a 10 années.

RE: how to get request parameters in velocity template

Liferay Master Publications: 654 Date d'inscription: 06/01/09 Publications récentes
#set ($current_url = $request.get("attributes").CURRENT_COMPLETE_URL)
#set ($paramName='n')
#set ($n6 = $httpUtil.getParameter($current_url, $paramName))

I've used this earlier and that worked for me.

Can you try below code which would print each value which helps to resolve what is not working ?
Request : $request
#set ($current_url = $request.get("attributes").CURRENT_COMPLETE_URL)
Current URL : $current_url
#set ($paramName='n')
HttpUtil : $httpUtil
#set ($n6 = $httpUtil.getParameter($current_url, $paramName))
n6 : $n6
thumbnail
Jerry Liu, modifié il y a 10 années.

RE: how to get request parameters in velocity template

Junior Member Publications: 47 Date d'inscription: 29/10/13 Publications récentes
I have been solved
as follows.
  #set ($serviceContext = $portal.getClass().forName("com.liferay.portal.service.ServiceContextThreadLocal").getServiceContext())
#set ($httpServletRequest = $serviceContext.getRequest())
#set($seminarId =$paramUtil.getLong($httpServletRequest, 'seminarId'))
maria pavlova, modifié il y a 10 années.

RE: how to get request parameters in velocity template

New Member Publications: 6 Date d'inscription: 06/05/13 Publications récentes
Does the request object need to be defined in a .vm file?

if I dump $request, it shows up as $request, same for any parameters in it.

thanks for any help
thumbnail
Baladhandapani Nagarajan, modifié il y a 9 années.

RE: how to get request parameters in velocity template

Junior Member Publications: 26 Date d'inscription: 12/01/15 Publications récentes
Hi All ,
Iam facing similar type of issue , can some one please help me here - We are in the process of migrating our project from 6.1 to 6.2

In my VM file : (This VM file is part of theme, We have embeded portlets as part of theme. Basically we are trying to read the 'contentName' parameter in the controller class and get the corresponding content from the documentum server to display it as part of embeded portlet.
----------------
Entry in VM file

$theme.runtime("embeddedWebContent_WAR_wp_INSTANCE_ftr40", "contentName=abc", "")

In my controller class
String contentName = request.getParameter("contentName");

Iam not getting the value "abc" in my contoller class , this code was working fine with 6.1 and this happening after our migration. The strange part is , If i create a new page and apply the same theme , then Iam getting the request parameter value in the controller class. (This is failing only for the existing pages and working fine with 6.1)

We cannot delete and reapply the theme for all the pages in production - I really appreciate your inputs !
thumbnail
David H Nebinger, modifié il y a 9 années.

RE: how to get request parameters in velocity template

Liferay Legend Publications: 14916 Date d'inscription: 02/09/06 Publications récentes
This came up recently, almost exactly the same as last time...

contentName is not namespaced so it will not be part of the portlet request parameters. You have to get the HTTP request and pull the parameter from there.
thumbnail
Baladhandapani Nagarajan, modifié il y a 9 années.

RE: how to get request parameters in velocity template

Junior Member Publications: 26 Date d'inscription: 12/01/15 Publications récentes
Thank you David , let me try and update you.
thumbnail
Baladhandapani Nagarajan, modifié il y a 9 années.

RE: how to get request parameters in velocity template

Junior Member Publications: 26 Date d'inscription: 12/01/15 Publications récentes
Hi David,

I tried converting to HttpRequest

HttpServletRequest originalRequest = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(request));
HttpServletRequest httpRequest = themeDisplay.getRequest();

String conName = httpRequest.getParameter("contentName");
String param = originalRequest.getParameter("contentName");

Still 'contentName' in the request is null.Again I want to insist that the same request parameter is not empty for the new applied theme page , the issue is happening only for the existing pages (request parameter content name is coming as null for the already existing pages)

Do I need to set the content Name prefixed with <portletnamespace/> in the VM file before I access in Controller class ?
thumbnail
David H Nebinger, modifié il y a 9 années.

RE: how to get request parameters in velocity template

Liferay Legend Publications: 14916 Date d'inscription: 02/09/06 Publications récentes
This argument makes no sense. A legacy page, one pre-upgrade, does not have the theme frame around it stored anywhere. It is still built by the portal using the available theme tied to the page at runtime.

Are you sure you're using the same theme on the legacy pages as the new pages?
thumbnail
Baladhandapani Nagarajan, modifié il y a 9 années.

RE: how to get request parameters in velocity template

Junior Member Publications: 26 Date d'inscription: 12/01/15 Publications récentes
Yes I agree , Iam using the same theme for the legacy (pre-upgrade) as well as the newly created blank page. I reapplied different themes on the newly created page , I don't face any issue in getting the request parameter from the VM file.
thumbnail
Baladhandapani Nagarajan, modifié il y a 9 années.

RE: how to get request parameters in velocity template

Junior Member Publications: 26 Date d'inscription: 12/01/15 Publications récentes
In this case (for the legacy pages) its forwarding to virtual page , that may be the reason Iam not getting directly from the portlet / http request. Iam planning to get the value from 'PortletPreference' object instead of request - Can some one suggest me to set the content name value in 'Portlet Preference' object in VM file and logic to retrieve it from the controller class.

I modified the entry in VM file / contoller , still Iam not able to get the 'contentName' value :


#set ($VOID = $velocityPortletPreferences.setValue("contentName", "abc"))
$theme.runtime("embeddedWebContent_WAR_wp_INSTANCE_ftr40", "contentName=abc", $velocityPortletPreferences.toString())
#set ($VOID = $velocityPortletPreferences.reset())

In my controller class
Enumeration names = preferences.getNames();

Iterated the 'names' , it doesn't printed out the content name - am I missing something ?
thumbnail
Julius Garcia, modifié il y a 8 années.

RE: how to get request parameters in velocity template

New Member Envoyer: 1 Date d'inscription: 03/08/15 Publications récentes
Here's a very simple solution...

e.g: .../?param1=Hello%20World
vm:
#set ($param1 = $request.getParameter('param1'))

##$param1 will have "Hello World" value
thumbnail
Fernando Fernandez, modifié il y a 7 années.

RE: how to get request parameters in velocity template

Expert Publications: 396 Date d'inscription: 22/08/07 Publications récentes
This page says $request is a javax.servlet.http.HttpServletRequest but this might cause some confusion because $request, in CMS templates is, in fact, an HashMap with lots of different objects of different classes.

If you want to find the URL with the parameters you can use:

$request.get('attributes').get('CURRENT_URL')


HTH

Fernando