Accessing User Information from JSR-168 compliant portlet

If you want to access users information such as first name and last name which is normally stored in coroporate directory in JSR-168 compliant way then use these steps
First add these entries in

<description xml:lang="en">User Given Name</description>
<description xml:lang="en">User Last name</description>

After that you should be able to access those two attributes in your java code by using code like this

Map userInfo = (Map)request.getAttribute(PortletRequest.USER_INFO);
if(userInfo != null){
String givenName = (String)userInfo.get("");
String lastName =(String)userInfo.get("");
response.getWriter().println("Hello " + givenName +" " + lastName);

At deployment time the portal can map the requested user profile attributes to the supported profile attributes or the portal can ignore the requested attributes.

No comments: