Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
gofri _
<SOLVED> Getting user info from jsf managed bean
June 26, 2008 2:15 AM
Answer

gofri _

Rank: Junior Member

Posts: 92

Join Date: March 2, 2007

Recent Posts

Hello!
I have a jsf portlet with backing and managed bean.
How to get current user data (id, e-mail etc...) from managed bean?
10x in advance
gofri _
RE: Getting user info from jsf managed bean
June 25, 2008 9:08 AM
Answer

gofri _

Rank: Junior Member

Posts: 92

Join Date: March 2, 2007

Recent Posts

OK, I figured how to get user and company id's:

FacesContext facesContext = FacesContext.getCurrentInstance();
RenderRequest renderRequest = (RenderRequest)facesContext.getExternalContext().getRequest();
Map userInfo =(Map)renderRequest.getAttribute(RenderRequest.USER_INFO);
String userId = userInfo.get("liferay.user.id");

Now the problem is with another user data...
Hans-Georg Menz
RE: Getting user info from jsf managed bean
June 26, 2008 12:47 AM
Answer

Hans-Georg Menz

Rank: Junior Member

Posts: 37

Join Date: June 30, 2007

Recent Posts

You might try something like

1UserServiceUtil.getUserById(userId).getEmailAddress()


I hope that helps.

Greetings,
Hans-Georg
jussi ss seppala
RE: Getting user info from jsf managed bean
June 26, 2008 1:23 AM
Answer

jussi ss seppala

Rank: New Member

Posts: 8

Join Date: May 15, 2008

Recent Posts

I have used following code which works fine:


private User getCurrentUser(){
User u = null;
FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext externalContext = fc.getExternalContext();
if (externalContext.getUserPrincipal() == null){
System.out.println("current principal is null");
}
else{
Long id = Long.parseLong(externalContext.getUserPrincipal().getName());
try {
u = UserLocalServiceUtil.getUserById(id);
}
catch (PortalException ex) {
Logger.getLogger(mybean.class.getName()).log(Level.SEVERE, null, ex);
}
catch (SystemException ex) {
Logger.getLogger(mybean.class.getName()).log(Level.SEVERE, null, ex);
}
}
return u;
}

Hope this helps!
-jussi
gofri _
RE: Getting user info from jsf managed bean
June 26, 2008 2:13 AM
Answer

gofri _

Rank: Junior Member

Posts: 92

Join Date: March 2, 2007

Recent Posts

Thanks for replies!
They helped.