Check current page url contents in liferay velocity template

Java picture Java · Jun 19, 2013 · Viewed 8.3k times · Source

I am trying to find out current page url contents and parameters in liferay Velocity(vm)file. I am able to get current page url by this way.

I have tried to decode url

 http://localhost:8080/web/guest/sign-in?p_p_id=45&p_p_lifecycle=0&_58_redirect=‌​%2Fgroup%2Femployee%2FmainForm%3FempName%3DABC

using following way

#set($absoluteUrl= $theme_display.getURLCurrent())
#set ($test=$httpUtil.decodeURL($absoluteUrl)) 

Now I am getting url as

/web/guest/sign-in?p_p_id=58&p_p_lifecycle=0&_58_redirect=/group/employee/mainForm?empName=ABC

Now I am trying to get value of empName by this way.

#set($empName= $request.getParameter("empName"))

But still unable to get anything? What I am missing? how can I get value of this parameter now?

Answer

Alessandro Alessandra picture Alessandro Alessandra · Jun 19, 2013

You can check substrings in velocity by this:

#set ($url = $themeDisplay.getURLCurrent())

#if($url.contains("&empName=ABC"))
The url contains the string <b>&empName=ABC<b>
#else
The url does not contain the string <b>&empName=ABC</b>
#end

If you want to check for request parameter existance prior to check its content:

#set($empName = $request.getParameter("empName"))

#if (!$empName) 
<h1>Parameter not found</h1>
#else
<h1>Parameter found: $empName</h1>
#end`

Tested in Liferay 6.1.1 ce ga2