Question

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?

Was it helpful?

Solution

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

OTHER TIPS

If url is like in this way:

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

Now we can decode this url as :

#set($url= $theme_display.getURLCurrent())
#set ($decodedUrl=$httpUtil.decodeURL($url)) 

So 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 we can get value of empName by this way:

#set($empName=$decodedUrl.split("empName=").get(1)) 

So we will get value of $empName=ABC

$themeDisplay.getScopeGroup().getPathFriendlyURL($themeDisplay.getLayout().isPrivateLayout(),$themeDisplay)+$layout.getGroup().friendlyURL

this will check if the page is private layout and will display /[web|group]/[site-name]/

Compare current URL:

if($portal.getCurrentURL($request) == "/home")

or

if($portal.getCurrentURL($request).indexOf("/demo-demo")>=0)

This returns all the URLs starting with 'demo-demo';

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top