Foros de discusión
how to get request parameters in velocity template
Jerry Liu, modificado hace 10 años.
how to get request parameters in velocity template
Junior Member Mensajes: 47 Fecha de incorporación: 29/10/13 Mensajes recientes
hi everybody!
as follows code
url:
But nothing was set.
What am I doing wrong?
thanks.
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.
meera prince, modificado hace 10 años.
RE: how to get request parameters in velocity template
Liferay Legend Mensajes: 1111 Fecha de incorporación: 8/02/11 Mensajes recientes
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
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
Jerry Liu, modificado hace 10 años.
RE: how to get request parameters in velocity template
Junior Member Mensajes: 47 Fecha de incorporación: 29/10/13 Mensajes recientesmeera 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.
Tejas Kanani, modificado hace 10 años.
RE: how to get request parameters in velocity template
Liferay Master Mensajes: 654 Fecha de incorporación: 6/01/09 Mensajes recientes#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
Jerry Liu, modificado hace 10 años.
RE: how to get request parameters in velocity template
Junior Member Mensajes: 47 Fecha de incorporación: 29/10/13 Mensajes recientes
I have been solved
as follows.
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, modificado hace 10 años.
RE: how to get request parameters in velocity template
New Member Mensajes: 6 Fecha de incorporación: 6/05/13 Mensajes recientes
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
if I dump $request, it shows up as $request, same for any parameters in it.
thanks for any help
Baladhandapani Nagarajan, modificado hace 9 años.
RE: how to get request parameters in velocity template
Junior Member Mensajes: 26 Fecha de incorporación: 12/01/15 Mensajes recientes
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 !
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 !
David H Nebinger, modificado hace 9 años.
RE: how to get request parameters in velocity template
Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
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.
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.
Baladhandapani Nagarajan, modificado hace 9 años.
RE: how to get request parameters in velocity template
Junior Member Mensajes: 26 Fecha de incorporación: 12/01/15 Mensajes recientes
Thank you David , let me try and update you.
Baladhandapani Nagarajan, modificado hace 9 años.
RE: how to get request parameters in velocity template
Junior Member Mensajes: 26 Fecha de incorporación: 12/01/15 Mensajes recientes
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 ?
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 ?
David H Nebinger, modificado hace 9 años.
RE: how to get request parameters in velocity template
Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
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?
Are you sure you're using the same theme on the legacy pages as the new pages?
Baladhandapani Nagarajan, modificado hace 9 años.
RE: how to get request parameters in velocity template
Junior Member Mensajes: 26 Fecha de incorporación: 12/01/15 Mensajes recientes
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.
Baladhandapani Nagarajan, modificado hace 9 años.
RE: how to get request parameters in velocity template
Junior Member Mensajes: 26 Fecha de incorporación: 12/01/15 Mensajes recientes
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 ?
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 ?
Julius Garcia, modificado hace 8 años.
RE: how to get request parameters in velocity template
New Member Mensaje: 1 Fecha de incorporación: 3/08/15 Mensajes recientes
Here's a very simple solution...
e.g: .../?param1=Hello%20World
vm:
#set ($param1 = $request.getParameter('param1'))
##$param1 will have "Hello World" value
e.g: .../?param1=Hello%20World
vm:
#set ($param1 = $request.getParameter('param1'))
##$param1 will have "Hello World" value
Fernando Fernandez, modificado hace 7 años.
RE: how to get request parameters in velocity template
Expert Mensajes: 396 Fecha de incorporación: 22/08/07 Mensajes recientes
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:
HTH
Fernando
If you want to find the URL with the parameters you can use:
$request.get('attributes').get('CURRENT_URL')
HTH
Fernando