Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Parag Negi
How to fetch vm variables like $group_id, etc on portlets jsp??
May 3, 2012 2:50 AM
Answer

Parag Negi

Rank: Junior Member

Posts: 29

Join Date: February 1, 2012

Recent Posts

Hi gang,

Is it possible to fetch vm variables like $group_id or $company_name directly to your portlets jsp?

i basically want to enable/visible some piece of code in my portlet's jsp, to only those people who match this criteria below:

(($permissionChecker.isOmniadmin())||$permissionChecker.isCompanyAdmin($themeDisplay.getCompanyId())|| $permissionChecker.isCommunityAdmin($themeDisplay.getScopeGroupId()))

These will be people with admin. priviledges only.

Is it possible to run the above code directly in my portlets jsp...
Please advise, any hep much appreciated...

Thanks,
Parag
Prakash Khanchandani
RE: How to fetch vm variables like $group_id, etc on portlets jsp??
May 3, 2012 3:11 AM
Answer

Prakash Khanchandani

Rank: Expert

Posts: 329

Join Date: February 10, 2011

Recent Posts

You can get these parameters from themeDisplay object in your JSP.

Have the following code in your JSPs to enable liferay specific objects:
1<%@ taglib uri="http://liferay.com/tld/theme"     prefix="liferay-theme" %>
2<liferay-theme:defineObjects />


Then you can use it like this in your JSP:
 1
 2<%
 3long groupId = themeDisplay.getScopeGroupId(); // current group
 4long userId = themeDisplay.getUserId(); // fetches the current logged in user's ID
 5User user = themeDisplay.getUser(); // current logged in user
 6Company company = themeDisplay.getCompany();
 7
 8//..... and so on
 9
10// also you get the permissionChecker object
11boolean isCAdmin = permissionChecker.isCompanyAdmin();
12boolean isGadmin = permissionChecker.isGroupAdmin(groupId);
13
14// .... and so on
15%>


Hope this helps.
Siju Thomas
RE: How to fetch vm variables like $group_id, etc on portlets jsp??
January 16, 2013 2:54 AM
Answer

Siju Thomas

Rank: New Member

Posts: 4

Join Date: July 27, 2011

Recent Posts

HI

#set ($companyName = "shark")
#set ($companyUrl = "http://www.shark.com")
#set ($companyEmail = "info@shark.com")
this is my custom variables saved in init_custom.vm . How to show this vm variables in my login.jsp in Hook.
I am using below code and its not working
Welcome to the <%=themeDisplay.companyName%>
Prakash Khanchandani
RE: How to fetch vm variables like $group_id, etc on portlets jsp??
January 16, 2013 3:19 AM
Answer

Prakash Khanchandani

Rank: Expert

Posts: 329

Join Date: February 10, 2011

Recent Posts

I think you are creating custom variables in velocity templates which you want to access in liferay's JSP.

AFAIK velocity variables created in the templates cannot be accessed inside JSP, but still will look if this is possible.

Can you provide a usecase as to why you would want to define new velocity variables and access them in your JSPs?

For accessing the company which you can use <%= themeDisplay.getCompany().getName() %>, though this won't give the company name changed in the velocity template, instead this gives the company name in which this portal page exists.
Siju Thomas
RE: How to fetch vm variables like $group_id, etc on portlets jsp??
January 16, 2013 3:48 AM
Answer

Siju Thomas

Rank: New Member

Posts: 4

Join Date: July 27, 2011

Recent Posts

Thank you Prakash.
I tried this method, but In my case I want to display the variables stored in the theme level to custom JSP and its not the main configuration values in the velocity variables.