1

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?

Java
  • 2,451
  • 10
  • 48
  • 85

4 Answers4

1

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

Alessandro Alessandra
  • 1,065
  • 12
  • 18
  • Thanks for quick reply. It works, but how can I check my `&empName` value as it will be dynamic. Means first we will check whether url contains `&empName` & if answer is yes we will need value of `&empName` , how can achieve it? – Java Jun 19 '13 at 10:44
  • and what if url contain parameter in format like empName%3DABC,then how we can get value of empName? – Java Jun 21 '13 at 14:52
  • Actually that is not a regular http request format. Can you post the whole url as example? – Alessandro Alessandra Jun 21 '13 at 17:12
  • my http url is `http://localhost:8080/group/employee/mainForm?empName=ABC` and when I paste that url in browser it changes as `http://localhost:8080/web/guest/sign-in?p_p_id=45&p_p_lifecycle=0&_58_redirect=%2Fgroup%2Femployee%2FmainForm%3FempName%3DABC` so how can check value of empName ? – Java Jun 24 '13 at 11:48
  • The url is rewritten by the server, and the only parameters I see are: p_p_id p_p_lifecycle _58_redirect – Alessandro Alessandra Jun 24 '13 at 13:48
  • You may want to check the last one that contains what seems to me an URL encoded string. But what I suppose is that the original url is rewritten because you have to login to the system, then the system itself will redirect to the original url. – Alessandro Alessandra Jun 24 '13 at 13:56
  • @yes you are right but how can I check that encoded string value? – Java Jun 25 '13 at 06:12
  • I have decoded `http://localhost:8080/web/guest/sign-in?p_p_id=45&p_p_lifecycle=0&_58_redirect=‌​%2Fgroup%2Femployee%2FmainForm%3FempName%3DABC ` please see my updated question – Java Jun 26 '13 at 05:31
  • @ Alessandro Alessandra finally it worked ,I have added my answer also. Thnaks Alessandro – Java Jun 27 '13 at 15:00
0

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

Java
  • 2,451
  • 10
  • 48
  • 85
0

$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]/

0

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';

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
mithunSalinda
  • 300
  • 3
  • 7