Reputation: 101
So here's what I'm trying to do:
I'm trying to call a servlet/controller (whatever i could get to work first) from a liferay theme.
Here's what i did: I made a controller named XController then generated a url to call it using:
#set ($embeddedPortletURL = $portletURLFactory.create($request, "workspace_WAR_xportlet", $page.plid, "RESOURCE_PHASE"))
<input id="workspaceSearchUrl" value="${embeddedPortletURL}" type="hidden">
Then for the ajax call, i used $("#workspaceSearchUrl").val() + "&p_p_mode=view&p_p_resource_id=doSomething"
as the url.
I was able to call the portlet no problem, however whenever i call portletRequest.getRemoteUser(), I get a userId of "2203" instead of the logged in user.
So... what exactly did i do wrong? And why is the getRemoteUser method returning me a number?
Edit: Just to be clear, other ajax calls to other controllers return a valid user id (text).
I also tried to call a servlet instead, however calling getRemoteUser returns a null. I guess this means that servlets don't share the session with the portal?
Upvotes: 0
Views: 624
Reputation: 976
You can get user object by userId like this.
User user = UserLocalServiceUtil.getUser(userId);
String name = user.getFirstname();
Upvotes: 0
Reputation: 196
If you can, try to use
User currentUser = PortalUtil.getUser(portletRequest);
long userId = currentUser.getUserId();
Upvotes: 1