-
1. Re: How can I get the user information in a GateIn portlet?
jdhogg May 20, 2010 3:55 AM (in response to joco)Hello Jozsef Szalai,
If I were you, next time, I would first search this forum or the GateIn doc or both for answers before posting a question – then you wouldn't have to wait. Anyway here is some information:
import org.exoplatform.container.PortalContainer;
import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.services.organization.OrganizationService;
import org.exoplatform.services.organization.User;
// Method to retrieve User details
User portletUser = null;
PortalRequestContext portalRequestContext = PortalRequestContext.getCurrentInstance();
// Get the id of the current user logged in
String remoteUserName = portalRequestContext.getRemoteUser();
OrganizationService organizationService = (OrganizationService)PortalContainer.getInstance().getComponentInstanceOfType(
OrganizationService.class);
if (remoteUserName != null) {
portletUser = organizationService.getUserHandler().findUserByName(remoteUserName);
}
You would then find the user details you need in the portletUser. See org.exoplatform.services.organization.User.
There also another way of doing it which the GateIn doc will tell you.
-
2. Re: How can I get the user information in a GateIn portlet?
joco May 21, 2010 4:55 AM (in response to jdhogg)Hello Benjamin,
Thanks for your hints it helped a lot, but I still got a null pointer exeption at the PortalRequestContext portalRequestContext = PortalRequestContext.getCurrentInstance(); line. I attached the error log, and the java and jsp files.
Do you have any idea?
Thanks,
Jozsef
-
UserName.java.zip 722 bytes
-
sysadm_index.jsp.zip 579 bytes
-
error_message.txt.zip 3.0 KB
-
-
3. Re: How can I get the user information in a GateIn portlet?
rraposa Nov 24, 2010 11:04 PM (in response to joco)This is an old post, but it needs correcting. The method:
PortalRequestContext.getCurrentInstance()
appears to not be in the API anymore. I found an alternate way to obtain a PortalRequestContext instance:
PortalRequestContext context = Util.getPortalRequestContext();
where Util is in the org.exoplatform.portal.webui.util package.
This needs to be fixed in the Reference Guide as well. The remainder of the code works fine. FWIW, if you're using Eclipse/JBDS you need to add the following JAR files to your build path:
gatein.ear/lib/exo.core.componenet.organization.api-xxx.jar
gaetin.ear/lib/exo.kernel.container-xxx.jar
gatein.ear/lib/exo.portal.webui.portal-5.1.x-epp.jar
-Rich