掲示板

how to get the userId in action class

11年前 に Kiran Kumar Boyini によって更新されました。

how to get the userId in action class

Expert 投稿: 287 参加年月日: 11/06/02 最新の投稿
Hi All,

I am using liferay 6.0.6.
I want to get the userId of user. for this I am using the following code.
long uId=new ThemeDisplay().getUserId();
System.out.println("userId "+uId);

But it is showing the following exception .
Current URL /web/guest/test? p_auth=pHYT34GE&p_p_id=EmployeePortlet_WAR_EmployeePortletportlet_INSTANCE_i0XI&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=column-2&p_p_col_count=1 generates exception: null
12:14:20,796 ERROR [jsp:996] java.lang.NullPointerException
java.lang.NullPointerException
at com.liferay.portal.theme.ThemeDisplay.getUserId(ThemeDisplay.java:159)


Thanks,
Kiran
thumbnail
11年前 に Juhi Kumari によって更新されました。

RE: how to get the userId in action class

Expert 投稿: 347 参加年月日: 11/12/12 最新の投稿
Hi Kiran,

Use these code to get userId in action class.
ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
long userId = themeDisplay.getUserId();


Regards
Juhi
11年前 に Kiran Kumar Boyini によって更新されました。

RE: how to get the userId in action class

Expert 投稿: 287 参加年月日: 11/06/02 最新の投稿
Thank you,

But I am getting same exception as I specified above
11年前 に Siby Mathew によって更新されました。

RE: how to get the userId in action class

Expert 投稿: 268 参加年月日: 11/03/04 最新の投稿
Hi Kiran,
The previous error is because you tried to instantiate the ThemeDisplay class .
Did you get it from the request object this time ?
Can you post your code.

Thanks,
Siby
11年前 に Kiran Kumar Boyini によって更新されました。

RE: how to get the userId in action class

Expert 投稿: 287 参加年月日: 11/06/02 最新の投稿
My code as follows


------------------------------------

public class EmployeePortlet extends MVCPortlet{

@Override
public void processAction( ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException {
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
long userId = themeDisplay.getUserId();
System.out.println("######LoginAction class########"+userId);

}
}



--------------------------------------------------

Thanks ,

Kiran
thumbnail
11年前 に Apoorva Prakash によって更新されました。

RE: how to get the userId in action class

Liferay Master 投稿: 658 参加年月日: 10/06/15 最新の投稿
Kiran Kumar Boyini:
public class EmployeePortlet extends MVCPortlet{

@Override
public void processAction( ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException {
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
long userId = themeDisplay.getUserId();
System.out.println("######LoginAction class########"+userId);
}
}



Hi Kiran,
Try putting the following code in try catch block and put e.printStackTrace() in catch block so that you can point to exact error, however this code is flawless.
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
	                                 long userId = themeDisplay.getUserId();
	                                 System.out.println("######LoginAction  class########"+userId);


Thanks and Regards,
Apoorva Prakash
11年前 に Siby Mathew によって更新されました。

RE: how to get the userId in action class

Expert 投稿: 268 参加年月日: 11/03/04 最新の投稿
Do you mean the themeDisplay object is null...or you are getting the userId as blank.
Also try out : PortalUtil.getUser(request);
11年前 に Ali Reza Akbarian によって更新されました。

RE: how to get the userId in action class

New Member 投稿: 6 参加年月日: 12/04/07 最新の投稿
perhaps you send a action request with guest role.
thumbnail
11年前 に Sreeraj AV によって更新されました。

RE: how to get the userId in action class

Regular Member 投稿: 239 参加年月日: 10/04/27 最新の投稿
Kiran Kumar Boyini:
My code as follows


------------------------------------

public class EmployeePortlet extends MVCPortlet{

@Override
public void processAction( ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException {
ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
long userId = themeDisplay.getUserId();
System.out.println("######LoginAction class########"+userId);

}
}



--------------------------------------------------

Thanks ,

Kiran





You can use the given code for getting current signed in user's id. Please note that, for a non-logged(guest) user this method will return 0 as the userId..

PortalUtil.getUserId(actionRequest);
9年前 に Prathyush S によって更新されました。

RE: how to get the userId in action class

New Member 投稿: 7 参加年月日: 15/03/26 最新の投稿
@Kiran,
Are you able to get the current user id/username in the "EmployeePortlet" class?
I have created a new portlet and deployed into liferay. Portlet have a servlet. In my servlet how to get the current liferay username or userid.
How to execute the "EmployeePortlet" class in you post.

Can you please help me how to get the user details in java class?If it is possible or not can you please tell me.


Regards,
Ramesh