Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Piña Kanpokaldean
Inconsistency in services between portlet and theme
May 29, 2013 1:01 AM
Answer

Piña Kanpokaldean

Rank: Junior Member

Posts: 34

Join Date: April 14, 2012

Recent Posts

Ok, I'm seriously puzzled by this one, so much that I don't even know where to start looking for a solution.

I need to display some stuff on the header for a specific role only, so I used velocity variables to access liferay user service and check for that. Only that it returned false for users I had assigned that role to. So I tried to figure out what was wrong. All ok to this point. However...

Can somebody please explain to me why, when I check on the portlet
1UserLocalServiceUtil.hasRoleUser(14905, userId)
I get a true, yet when I ask on the theme
1$UserLocalService.hasRoleUser(14905, $user_id)
I get a false? In the same exact page, the header tells me it doesn't have that role while the body tells me it does.

I even checked for the user Id, it's both the same as would be expected. It's the same call right? What am I missing here?

If somebody could give me a pointer as to why this happens, I would really appreciate it, as it makes no sense to me.
Oliver Bayer
RE: Inconsistency in services between portlet and theme
May 29, 2013 2:16 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 829

Join Date: February 18, 2009

Recent Posts

Hi Pina,

not sure what is going wrong there so I can only give some debugging hints emoticon.

Once I had similar problem in a theme where I don't get any value from a service. The problem was that the id parameter value was ok but in velocity it was the wrong type: string instead of an integer. So as first step can you please try to insert an existing user id static in your code (the same way as you've done it for the first parameter 14905)? If it's working with a hard coded user id you should search for a method which returns the id in the required type.

HTH Oli
Piña Kanpokaldean
RE: Inconsistency in services between portlet and theme
May 29, 2013 3:27 AM
Answer

Piña Kanpokaldean

Rank: Junior Member

Posts: 34

Join Date: April 14, 2012

Recent Posts

Thanks for the tip, it didn't work but having confirmation that I am indeed calling the same place is already enough to motivate me back into figuring out what's up here. I was starting to come up with all kinds of crazy conspiracy theories about replaced services and the like, and my head hurts.

I'll see if the theme response was cached somehow, try some different themes, test out usergroups instead of roles, whatever. Something's bound to work, eventually.
Parikshit Sharma
RE: Inconsistency in services between portlet and theme
May 29, 2013 3:35 AM
Answer

Parikshit Sharma

Rank: New Member

Posts: 21

Join Date: January 16, 2013

Recent Posts

Piña Kanpokaldean:
Ok, I'm seriously puzzled by this one, so much that I don't even know where to start looking for a solution.

I need to display some stuff on the header for a specific role only, so I used velocity variables to access liferay user service and check for that. Only that it returned false for users I had assigned that role to. So I tried to figure out what was wrong. All ok to this point. However...

Can somebody please explain to me why, when I check on the portlet
1UserLocalServiceUtil.hasRoleUser(14905, userId)
I get a true, yet when I ask on the theme
1$UserLocalService.hasRoleUser(14905, $user_id)
I get a false? In the same exact page, the header tells me it doesn't have that role while the body tells me it does.

I even checked for the user Id, it's both the same as would be expected. It's the same call right? What am I missing here?

If somebody could give me a pointer as to why this happens, I would really appreciate it, as it makes no sense to me.


Hi Piña Kanpokaldean,
I have no idea in which version of LR you are working but I have tried the below code in LR6.1.20 and it's work fine for me,get true in theme.

1
2#set($userLocalService=$serviceLocator.findService('com.liferay.portal.service.UserLocalService'))
3$userLocalService.hasRoleUser($getterUtil.getLong(13702),$user_id)
Piña Kanpokaldean
RE: Inconsistency in services between portlet and theme
May 29, 2013 5:35 AM
Answer

Piña Kanpokaldean

Rank: Junior Member

Posts: 34

Join Date: April 14, 2012

Recent Posts

Holy shit, I gave it a try just out of desperation, but it actually worked! Thanks!

I guess I forgot to define $UserLocalService, or thought it was already defined by default... not sure, I'll go check on what I've written before and clear my mind. I'm pretty sure I got an example where I didn't have to define it myself, but that was 6.0 and now I'm working on 6.1 so things may have changed...

Anyway, thanks again. I wasn't expecting a direct copy-paste solution, but sure is nice that it happened.

Edit: Just checked my old file, the definition was indeed there but happened somewhere else. My bad.