Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Arvind Gupta
Role not coming in hook
March 7, 2013 3:11 AM
Answer

Arvind Gupta

Rank: Junior Member

Posts: 29

Join Date: December 17, 2012

Recent Posts

I am working Liferay6.1.1. I was suppose to enable dockbar only for the user who has 'DockbarRole'. I followed below stpes:

1. Created a ''DockbarRole'' and assigned two members(One of this member is already having a Aministrator role).
2. Created a Hook and override the view.jsp where i checked the "'DockbarRole'" and accordingly showed the Dockbar.
3. I am able to retrive the users role only if he is having administrator role, if user do not have the administrator roles the role list is coming empty.

Below is my code to retrive the roles in hook:


boolean isDockbarUser=false;
if (request.getUserPrincipal() != null) {
List rapdrpRoles = RoleServiceUtil.getUserRoles(user.getUserId());
String name;
for (int i = 0; i < rapdrpRoles.size(); ++i) {
name = ((Role)rapdrpRoles.get(i)).getName();
if (("DockbarRole").equals(name) ) {
isDockbarUser = true;
}
}
}
Renata Siega
RE: Role not coming in hook
March 12, 2013 4:40 AM
Answer

Renata Siega

Rank: Junior Member

Posts: 34

Join Date: October 29, 2012

Recent Posts

Did you find out why the role is not coming?
Milen Dyankov
RE: Role not coming in hook
March 12, 2013 6:02 AM
Answer

Milen Dyankov

LIFERAY STAFF

Rank: Regular Member

Posts: 237

Join Date: October 30, 2012

Recent Posts

I would guess the user executing your code does not have permission to see the role. Try using RoleLocalServiceUtil instead of RoleServiceUtil as it does not check for permissions.
Manish Yadav
RE: Role not coming in hook
March 12, 2013 6:11 AM
Answer

Manish Yadav

Rank: Expert

Posts: 449

Join Date: May 26, 2012

Recent Posts

Check with below code ....may be it will help you

1
2boolean isDockbarUser=false;
3 (Role role1 : RoleLocalServiceUtil.getUserRoles(user.getUserId())) {
4                    if (role1.getName().equalsIgnoreCase("DockbarRole")) {
5                            boolean isDockbarUser=true;
6                            break;
7                    }
Arvind Gupta
RE: Role not coming in hook
March 13, 2013 5:52 AM
Answer

Arvind Gupta

Rank: Junior Member

Posts: 29

Join Date: December 17, 2012

Recent Posts

Thanks Milen and Manish it resolved my issue.