[HOWTO] Personalization - Getting current user attributes

Portals are all about personalization, and Liferay is no different.

I mean, there are many, many other things involved in portals other than personalization. But none of them really make sense without it.

Personalization is the dressing that makes your portal salad bearable. So, it has to be pretty good dressing.

Beyond the portal and personalization, we have the reason the portal exists at all: Portlets. Portlets are the ingredients needed to make a portal salad worth eating.

  1. You have your greens (the hard working portlets: E-Commerce, BI, BPM, CMS, etc.).
  2. Then you have your non-green veggies (Email, Forums, Blogs, Wiki, etc.).
  3. Finally you have your crutons and bacon bits, the stuff we know we can live without but just can't bring ourselves to leave out (social networking and other generally superfluous gadgets, widgetry, and such).

Yet it doesn't end there, it's gotta be MY salad, not someone else's... and it's gotta have MY name on it too. Who wants to eat someone else's food anyway...

That said, personalization at the portlet level is very important. There are two types of portlet personalization mechanisms available in Liferay.

  1. Personalization defined by the Portlet spec(s) (low fat, low cal. dressing)
  2. Liferay personalization (fatty, rich, tasty dressing)

Let's go through putting both to use in your Portlet application and then you can decide for yourself which best suites your diet.

Personalizaton via Portlet spec(s)

Both the 1.0 version and 2.0 (upcomming) versions of the spec define a mechanism called "user-attributes" defined as such:

"The deployment descriptor of a portlet application must define the user attribute names the portlets use. The following example shows a section of a deployment descriptor defining a few user attributes:

<portlet-app>
	...
	<user-attribute>
		<description>User Given Name</description>
		<name>user.name.given</name>
	</user-attribute>
	<user-attribute>
		<description>User Last Name</description>
		<name>user.name.family</name>
	</user-attribute>
	<user-attribute>
		<description>User eMail</description>
		<name>user.home-info.online.email</name>
	</user-attribute>
	<user-attribute>
		<description>Company Organization</description>
		<name>user.business-info.postal.organization</name>
	</user-attribute>
	...
<portlet-app>
A deployer must map the portlet application’s logical user attributes to the corresponding user attributes offered by the runtime environment. At runtime, the portlet container uses this mapping to expose user attributes to the portlets of the portlet application. User attributes of the runtime environment not mapped as part of the deployment process must not be exposed to portlets."

[JavaTM Portlet Specification, version 1.0, PLT.17.1]

This means that without having to do anything other than configuration, the portlet is requesting access to the defined user attributes. The list of available attributes can be found in the spec docs.

The next part is of course getting access to those user attributes at runtime.

Here is a complete JSP which handles getting the user.name.given attribute.

<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>

<%@ page import="javax.portlet.PortletRequest"%>
<%@ page import="java.util.Map"%>

<portlet:defineObjects />

<%
Map userInfo = (Map)renderRequest.getAttribute(PortletRequest.USER_INFO);
String givenName = (userInfo != null) ? (String)userInfo.get("user.name.given") : "";
%>

Given Name: <%= givenName %>

The result looks something like the following:

[Image 1]

That's 100% spec complient and includes the following list of attributes:

package com.liferay.portlet;

public class UserAttributes {

	// Mandatory Liferay attributes

	public static final String LIFERAY_COMPANY_ID = "liferay.company.id";

	public static final String LIFERAY_USER_ID = "liferay.user.id";

	public static final String USER_NAME_FULL = "user.name.full";

	// See page 119 of the JSR 168 spec

	public static final String USER_BDATE = "user.bdate";

	public static final String USER_GENDER = "user.gender";

	public static final String USER_EMPLOYER = "user.employer";

	public static final String USER_DEPARTMENT = "user.department";

	public static final String USER_JOBTITLE = "user.jobtitle";

	public static final String USER_NAME_PREFIX = "user.name.prefix";

	public static final String USER_NAME_GIVEN = "user.name.given";

	public static final String USER_NAME_FAMILY = "user.name.family";

	public static final String USER_NAME_MIDDLE = "user.name.middle";

	public static final String USER_NAME_SUFFIX = "user.name.suffix";

	public static final String USER_NAME_NICKNAME = "user.name.nickName";

	public static final String USER_HOME_INFO_POSTAL_NAME = "user.home-info.postal.name";

	public static final String USER_HOME_INFO_POSTAL_STREET = "user.home-info.postal.street";

	public static final String USER_HOME_INFO_POSTAL_CITY = "user.home-info.postal.city";

	public static final String USER_HOME_INFO_POSTAL_STATEPROV = "user.home-info.postal.stateprov";

	public static final String USER_HOME_INFO_POSTAL_POSTALCODE = "user.home-info.postal.postalcode";

	public static final String USER_HOME_INFO_POSTAL_COUNTRY = "user.home-info.postal.country";

	public static final String USER_HOME_INFO_POSTAL_ORGANIZATION = "user.home-info.postal.organization";

	public static final String USER_HOME_INFO_TELECOM_TELEPHONE_INTCODE = "user.home-info.telecom.telephone.intcode";

	public static final String USER_HOME_INFO_TELECOM_TELEPHONE_LOCCODE = "user.home-info.telecom.telephone.loccode";

	public static final String USER_HOME_INFO_TELECOM_TELEPHONE_NUMBER = "user.home-info.telecom.telephone.number";

	public static final String USER_HOME_INFO_TELECOM_TELEPHONE_EXT = "user.home-info.telecom.telephone.ext";

	public static final String USER_HOME_INFO_TELECOM_TELEPHONE_COMMENT = "user.home-info.telecom.telephone.comment";

	public static final String USER_HOME_INFO_TELECOM_FAX_INTCODE = "user.home-info.telecom.fax.intcode";

	public static final String USER_HOME_INFO_TELECOM_FAX_LOCCODE = "user.home-info.telecom.fax.loccode";

	public static final String USER_HOME_INFO_TELECOM_FAX_NUMBER = "user.home-info.telecom.fax.number";

	public static final String USER_HOME_INFO_TELECOM_FAX_EXT = "user.home-info.telecom.fax.ext";

	public static final String USER_HOME_INFO_TELECOM_FAX_COMMENT = "user.home-info.telecom.fax.comment";

	public static final String USER_HOME_INFO_TELECOM_MOBILE_INTCODE = "user.home-info.telecom.mobile.intcode";

	public static final String USER_HOME_INFO_TELECOM_MOBILE_LOCCODE = "user.home-info.telecom.mobile.loccode";

	public static final String USER_HOME_INFO_TELECOM_MOBILE_NUMBER = "user.home-info.telecom.mobile.number";

	public static final String USER_HOME_INFO_TELECOM_MOBILE_EXT = "user.home-info.telecom.mobile.ext";

	public static final String USER_HOME_INFO_TELECOM_MOBILE_COMMENT = "user.home-info.telecom.mobile.comment";

	public static final String USER_HOME_INFO_TELECOM_PAGER_INTCODE = "user.home-info.telecom.pager.intcode";

	public static final String USER_HOME_INFO_TELECOM_PAGER_LOCCODE = "user.home-info.telecom.pager.loccode";

	public static final String USER_HOME_INFO_TELECOM_PAGER_NUMBER = "user.home-info.telecom.pager.number";

	public static final String USER_HOME_INFO_TELECOM_PAGER_EXT = "user.home-info.telecom.pager.ext";

	public static final String USER_HOME_INFO_TELECOM_PAGER_COMMENT = "user.home-info.telecom.pager.comment";

	public static final String USER_HOME_INFO_ONLINE_EMAIL = "user.home-info.online.email";

	public static final String USER_HOME_INFO_ONLINE_URI = "user.home-info.online.uri";

	public static final String USER_BUSINESS_INFO_POSTAL_NAME = "user.business-info.postal.name";

	public static final String USER_BUSINESS_INFO_POSTAL_STREET = "user.business-info.postal.street";

	public static final String USER_BUSINESS_INFO_POSTAL_CITY = "user.business-info.postal.city";

	public static final String USER_BUSINESS_INFO_POSTAL_STATEPROV = "user.business-info.postal.stateprov";

	public static final String USER_BUSINESS_INFO_POSTAL_POSTALCODE = "user.business-info.postal.postalcode";

	public static final String USER_BUSINESS_INFO_POSTAL_COUNTRY = "user.business-info.postal.country";

	public static final String USER_BUSINESS_INFO_POSTAL_ORGANIZATION = "user.business-info.postal.organization";

	public static final String USER_BUSINESS_INFO_TELECOM_TELEPHONE_INTCODE = "user.business-info.telecom.telephone.intcode";

	public static final String USER_BUSINESS_INFO_TELECOM_TELEPHONE_LOCCODE = "user.business-info.telecom.telephone.loccode";

	public static final String USER_BUSINESS_INFO_TELECOM_TELEPHONE_NUMBER = "user.business-info.telecom.telephone.number";

	public static final String USER_BUSINESS_INFO_TELECOM_TELEPHONE_EXT = "user.business-info.telecom.telephone.ext";

	public static final String USER_BUSINESS_INFO_TELECOM_TELEPHONE_COMMENT = "user.business-info.telecom.telephone.comment";

	public static final String USER_BUSINESS_INFO_TELECOM_FAX_INTCODE = "user.business-info.telecom.fax.intcode";

	public static final String USER_BUSINESS_INFO_TELECOM_FAX_LOCCODE = "user.business-info.telecom.fax.loccode";

	public static final String USER_BUSINESS_INFO_TELECOM_FAX_NUMBER = "user.business-info.telecom.fax.number";

	public static final String USER_BUSINESS_INFO_TELECOM_FAX_EXT = "user.business-info.telecom.fax.ext";

	public static final String USER_BUSINESS_INFO_TELECOM_FAX_COMMENT = "user.business-info.telecom.fax.comment";

	public static final String USER_BUSINESS_INFO_TELECOM_MOBILE_INTCODE = "user.business-info.telecom.mobile.intcode";

	public static final String USER_BUSINESS_INFO_TELECOM_MOBILE_LOCCODE = "user.business-info.telecom.mobile.loccode";

	public static final String USER_BUSINESS_INFO_TELECOM_MOBILE_NUMBER = "user.business-info.telecom.mobile.number";

	public static final String USER_BUSINESS_INFO_TELECOM_MOBILE_EXT = "user.business-info.telecom.mobile.ext";

	public static final String USER_BUSINESS_INFO_TELECOM_MOBILE_COMMENT = "user.business-info.telecom.mobile.comment";

	public static final String USER_BUSINESS_INFO_TELECOM_PAGER_INTCODE = "user.business-info.telecom.pager.intcode";

	public static final String USER_BUSINESS_INFO_TELECOM_PAGER_LOCCODE = "user.business-info.telecom.pager.loccode";

	public static final String USER_BUSINESS_INFO_TELECOM_PAGER_NUMBER = "user.business-info.telecom.pager.number";

	public static final String USER_BUSINESS_INFO_TELECOM_PAGER_EXT = "user.business-info.telecom.pager.ext";

	public static final String USER_BUSINESS_INFO_TELECOM_PAGER_COMMENT = "user.business-info.telecom.pager.comment";

	public static final String USER_BUSINESS_INFO_ONLINE_EMAIL = "user.business-info.online.email";

	public static final String USER_BUSINESS_INFO_ONLINE_URI = "user.business-info.online.uri";

}

It should be noted that as of right now, we haven't implemented the additonal attributes defined in javax.portlet.PortletRequest.P3PUserInfos, of the current version 2.0 recommendation.



Liferay Personalizaton

Liferay personalization provides access to pojos which can be interacted with in a much richer fashion than above. It also ties your application to Liferay so, if you plan to target more than just Liferay as plaform, don't use it.

The easiest way to take avantage of Liferay personalization is to use a couple of Liferay's taglibs; more precisely, the liferay-theme and liferay-ui taglibs.

Since these are not included in a deployed portlet by default, add the following property to your liferay-plugin-package.properties file:

portal.dependency.tlds=\
    liferay-ui.tld,\
    liferay-theme.tld

and the following taglib definitions to your web.xml:

	<taglib>
		<taglib-uri>http://liferay.com/tld/theme</taglib-uri>
		<taglib-location>/WEB-INF/tld/liferay-theme.tld</taglib-location>
	</taglib>
	<taglib>
		<taglib-uri>http://liferay.com/tld/ui</taglib-uri>
		<taglib-location>/WEB-INF/tld/liferay-ui.tld</taglib-location>
	</taglib>

Now that we have the right tools available, let's start with the very simplest example that gives us the most bang.

<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>

<liferay-theme:defineObjects />
<portlet:defineObjects />

<liferay-ui:user-display userId="<%= user.getUserId() %>" />

The result of the above JSP code is something like the following:

[Image 2]

Now you might be asking yourself "Where did that user object suddenly come from?"

The answer is simple! It comes from the <liferay-theme:defineObjects /> tag we used. This tag puts a whole bunch of context sensitive objects into our JSP page context, including the com.liferay.portal.model.User pojo associated with the current user..

The objects that are injected into the pageContext by the <liferay-theme:defineObjects /> tag are:

  • themeDisplay - com.liferay.portal.theme.ThemeDisplay
  • company - com.liferay.portal.model.Company
  • account - com.liferay.portal.model.Account (deprecated)
  • user - com.liferay.portal.model.User
  • realUser - com.liferay.portal.model.User
  • contact - com.liferay.portal.model.Contact
  • ?layout - com.liferay.portal.model.Layout
  • ?layouts - List<com.liferay.portal.model.Layout>
  • plid - java.lang.Long
  • ?layoutTypePortlet - com.liferay.portal.model.LayoutTypePortlet
  • portletGroupId - java.lang.Long
  • permissionChecker - com.liferay.portal.security.permission.PermissionChecker
  • locale - java.util.Locale
  • timeZone - java.util.TimeZone
  • theme - com.liferay.portal.model.Theme
  • colorScheme - com.liferay.portal.model.ColorScheme
  • portletDisplay - com.liferay.portal.theme.PortletDisplay

Wow, now that's lots of bacon!!! I like bacon!

I won't try to explain the use of all of these objects here on this post. Suffice it to say that after exploring all of these objects and the remaining tags available to you in the Liferay taglibs, you shouldn't run out of personalization options any time soon.

You can't use JSP taglibs?

Never fear! All these objects are actually obtained by various getter methods on the com.liferay.portal.theme.ThemeDisplay object. We just put them right into the page context to cut down on code.

So, all you need is the themeDisplay object, and you can get it from the portletRequest like so:

ThemeDisplay themeDisplay = (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);

themeDisplay.getCompany();
themeDisplay.getAccount();
themeDisplay.getUser();
themeDisplay.getRealUser();
themeDisplay.getContact();

if (themeDisplay.getLayout() != null) {
	themeDisplay.getLayout();
}

if (themeDisplay.getLayouts() != null) {
	themeDisplay.getLayouts();
}

themeDisplay.getPlid());

if (themeDisplay.getLayoutTypePortlet() != null) {
	themeDisplay.getLayoutTypePortlet();
}

new Long(themeDisplay.getPortletGroupId());
themeDisplay.getPermissionChecker();
themeDisplay.getLocale();
themeDisplay.getTimeZone();
themeDisplay.getTheme();
themeDisplay.getColorScheme();
themeDisplay.getPortletDisplay();

Well, feel to ask questions about the ones for which the meanings are less than obvious. The Message Boards are also full of answers regarding various personalization topics. And remember to have a look at the API docs on the site for the methods provided from each of these objects.

Blogs
I like this HOWTO very much, but I still have a question. Maybe you can help me with that. Do you know how to get the req in

ThemeDisplay themeDisplay = (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);

in an ICEFaces portlet?
Thank you very much!

I'm not a *Faces export by any means, BUT I think that in general you can do something like this:

FacesContext fCtx = FacesContext.getCurrentInstance();

PortletRequest req = (PortletRequest)fCtx.getExternalContext().getRequest();

_themeDisplay = (ThemeDisplay)req.getAttribute(WebKeys.THEME_DISPLAY);

Please note that a common mistake with *Faces is that "some" requests aren't actually handled by the portal. Those will never have portal attributes, like "ThemeDisplay" in them, unless you add some sort of special handling.
Insert the following in web.xml
<context-param>
<param-name>com.icesoft.faces.hiddenPortletAttributes</param-name>
<param-value>THEME_DISPLAY</param-value>
</context-param>

Then you can access Theme Display by adding the code in your Managed Bean:
avax.portlet.PortletRequest req = (javax.portlet.PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
RenderRequest renderRequest = (RenderRequest) req.getAttribute("javax.portlet.request");
ThemeDisplay _theme = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);

System.err.println(_theme.getCompany() + " : " + _theme.getCompanyId());
System.out.println(_theme.getUser().getFullName() + " : " + _theme.getUserId());
<b>No tag "user-display" defined in tag library imported with prefix "liferay-ui"</b> error..

there is no file liferay-plugin-package.properties either ? ...
as im the only unhappy one here im hoping its just me being a liferay anoying noob emoticon
What environment are you working with a portlet or a theme? In ext or SDK?
Hi Ray,
I am trying to get this working, but I get Given Name : null.
First of all I am working with a portlet and I am using SDK 5.2.2.
I am not sure where to put the <portlet-app> configurations. Is there something that is already written somewhere or shall I write it in some file, in that case, which one. If it is already written, what else can be wrong?
Thanks!
The elements under "portlet-app" go in the portlet.xml file of your plugin.

See the JSP spec for relevant details about that (or the examples above).
I did try to put it there but I still get the same answer, Given name: null.
Does it matter where in the file I put it? I have tried both in the top between the <portlet-app>-tags and in the end, still between them, but nothing works.
Thanks for this post. I have a question on a topic related to personalization.

When a logged user adds, positions or emove a portlet on a page of the portal, the page configuration is persisted somewhere; so the user, for his next session, will retrieve the his set of portlets, in his specific layout. For example,
- user Joe has a News portlet on the left and Wheather portlet on the right;
- user Sarah has a Weather portlet on top and a Map Viewer portlet on the bottom.
The same applies for the specific list of pages, with chosen layout templates, configured by each user.

What is exactly the name for this kind of settings (in Liferay or elsewhere)?
Is this standardized (JSR-168 or JSR-286)?

To be clear, my question is at the level of portal page. I DON'T speak here about
- preferences/configuration of one specific portlet
- Liferay themes
- user profiles (name, address, etc)

Thanks
Hi Ray,

Is it possible to achieve rules based personalization or say unified user profile attributes like one available with weblogic ?
Thanks
Raju
Do you have some references I can read on both these topics? I've never used the terminology, so I can't really comment on whether we can or can't do it.

Thanks
Sorry for delay.
Rules based personalization: based on embedded business rules like say if A then B defined say using a drools rules engine or like web sphere which has a rules engine as part of personalization .
Useful link:
http://www.atgsolutionsstrategy.com/2008/09/personalization.html

Unified user Profile is more Weblogic Portal specific which allows to create and manage unified user profiles for personalization.
Heres a useful bea link:
http://edocs.bea.com/wlp/docs92/users/uup.html

Does liferay support use of say drools rules engine just like it supports jBPM for process management .

Thanks
Raju
hi
i got good idea about personalization, but i have 1 question that, if i want to change the theme users to user how will i do?
I'll make a quick blog post about this since I now have 2 inquires of how to do this.

Coming soon!
Thanks for the post Ray. I would like to fetch the Liferay logged User's UserGroup Names. How can I do that?
I was trying to figure out how to get the phone number of a user. I am using the themeDisplay object and I just can't find the phone numbers.
Hi Ray,

Very helpful post! But I am having trouble with one specific attribute, Job Title. I've followed the code exactly and all the other attributes are retrieved correctly but Job Title keeps on coming back NULL. I am using LifeRay 5.2.2.

Please let me know if you've or anyone has encountered this before or if this is a known issue.

Thanks,
Garry
Hi,
I have a question with regard to personalization, since portlets reside on the same JVM can I use the static Util class which are also available through spring to create and remove content like shown below using my Icefaces portlets Managed Bean class:

public class KeyAccess {

public void invoke() {
try {
javax.portlet.PortletRequest req = (javax.portlet.PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
RenderRequest renderRequest = (RenderRequest) req.getAttribute("javax.portlet.request");
ThemeDisplay _theme = (ThemeDisplay) req.getAttribute(WebKeys.THEME_DISPLAY);

System.err.println(_theme.getCompany() + " : " + _theme.getCompanyId());
System.out.println(_theme.getUser().getFullName() + " : " + _theme.getUserId());

com.liferay.portlet.announcements.service.AnnouncementsEntryLocalServiceUtil ann = new AnnouncementsEntryLocalServiceUtil();

com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil msg = new MBMessageLocalServiceUtil();
MBMessage message = msg.createMBMessage(1001);
message.setBody("My Simple Message");
message.setSubject("TEST Message");
message.setCompanyId(_theme.getCompanyId());
message.setUserId(_theme.getUserId());
message.setUserName(_theme.getUser().getFullName());
message.setCategoryId(1);
msg.updateMBMessage(message);

// AnnouncementsEntry entry = ann.createAnnouncementsEntry(109);
// Calendar cal = Calendar.getInstance();
// entry.setCompanyId(_theme.getCompanyId());
// entry.setUserId(_theme.getUserId());
// entry.setAlert(true);
// entry.setContent("adfads asdfasdf asdfsadf asdfasdf");
// entry.setCreateDate(cal.getTime());
// entry.setDisplayDate(cal.getTime());
// ann.updateAnnouncementsEntry(entry);
} catch (SystemException ex) {
Logger.getLogger(KeyAccess.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Not sure why you have to get the RenderRequest from the already obtained PortletRequest (should both the be the same objects), but perhaps this is a quirck with faces I'm not aware of...

Otherwise try this:
----------------------------------------
try{
RenderRequest renderRequest = ...

ThemeDisplay _theme = (ThemeDisplay)renderRequest.getAttribute(
WebKeys.THEME_DISPLAY);

List<ObjectValuePair<String, byte[]>> files = Collections.EMPTY_LIST;

ServiceContext serviceContext = ServiceContextFactory.getInstance(
MBMessage.class.getName(), renderRequest);

MBMessageLocalServiceUtil.addMessage(
_theme.getUserId(), _theme.getUser().getFullName(),
_theme.getScopeGroupId(),
MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID, "TEST Message",
"My Simple Message", files, false,
MBThreadConstants.PRIORITY_NOT_GIVEN, true, serviceContext);
}
catch (SystemException ex) {
...
}
----------------------------------------

Furthermore, there is no need to initialize the services as these are singletons that are ready for use. Just invoke their static methods.

Also, use the factory add/delete/update methods from core services unless you are ABSOLUTELY sure what you are doing.
Thank you Ray, I really appreciate your immediate assistance. I hope I can document my full development approach soon.
Very nice article. Do you know how to also get at the "custom fields" values for a particular object? I added a custom field for the Organization type but cannot seem to get the values that are at a particular object. I posted the question in the forum. Not sure if you knew. (http://www.liferay.com/community/forums/-/message_boards/message/5857914?_19_preview=false)
Thanks, but I am having trouble getting your example to work. Since I am completely new to Liferay, I am sure, my problem is an easy one, but googling didn't help.

Here's what I did:

Using the Eclipse Liferay IDE, I created a new Portlet. In the view.jsp, I have this code:

<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>

<%@ page import="javax.portlet.PortletRequest"%>
<%@ page import="java.util.Map"%>

<portlet:defineObjects />

<%
Map userInfo = (Map)renderRequest.getAttribute(PortletRequest.USER_INFO);
String givenName = (userInfo != null) ? (String)userInfo.get("user.name.given") : "<empty>";
String loginId = (userInfo != null) ? (String) userInfo.get("user.login.id") : "<empty>";
String userPassword = PortalUtil.getUserPassword(request);
%>

Given Name: <%= givenName %>
Login ID: <%= loginId %>
Password: <%= userPassword %>


After deployment, the page shows "Given Name: null, Login ID: null, Password: null", whether I am currently logged in or not. Is there anything I can do to solve this issue? What have I missed? Thanks!
Arrgh! Ok, sorry: portlet-app. I see. I forgot to include them. Sorry!!

However, the password still is not shown, because I couldn't add that one to the portlet-app tags. How do I make the password bit available? Thanks!
I'm using liferay 6. I would like to get current user attributes in the controller.

my methods looks like this, and i'm not using annotation (instead of renderingRequests?)

@RequestMapping(params = "action=myMethod")
public String myMethod(ModelMap model) throws Exception {

// Here I want to get current name and save something with his/her name to the database (over a service)

model.put("done", isSuccessfull);
return "finished";
}
how can i do this here, to get some name of current logged in person?
Okay, not very compicated. Described as aboth. But i will give some more explicite example

go to YourController.java

I) Portlet.xml
Do as described above in main post under "Personalizaton via Portlet spec(s)"

II) Controller.java
1) Define
----------------------------------------------------------------
public class YourController.java
[...]
@Inject // I'm not sure if i have to inject this, but i did.
protected PortletRequest portRequest;

protected Map mapReq;

[...]

2) Code request in your method
----------------------------
@RequestMapping(params = "action=yourMethod")
public String pushIt(ModelMap model) throws Exception {
Map userInfo =(Map)portRequest.getAttribute(PortletRequest.USER_INFO);
String givenName = (userInfo != null) ? (String)userInfo.get("user.name.given") : "";
model.put("getQuickMessages", countNewMessages());
return "thanx";
}
Ray: I think I've followed your instructions to the dot. Here's my Portlet.xml --

<?xml version="1.0"?>

<portlet-app
version="2.0"
xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
>


<portlet>
<portlet-name>my-email</portlet-name>
<display-name>My Email</display-name>
<portlet-class>com.liferay.util.bridges.mvc.MVCPortlet</portlet-class>
<init-param>
<name>view-jsp</name>
<value>/view.jsp</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
</supports>
<portlet-info>
<title>My Email</title>
<short-title>My Email</short-title>
<keywords>My Email</keywords>
</portlet-info>
<security-role-ref>
<role-name>administrator</role-name>
</security-role-ref>
<security-role-ref>
<role-name>guest</role-name>
</security-role-ref>
<security-role-ref>
<role-name>power-user</role-name>
</security-role-ref>
<security-role-ref>
<role-name>user</role-name>
</security-role-ref>

</portlet>

<user-attribute>
<description>User Given Name</description>
<name>user.name.given</name>
</user-attribute>
<user-attribute>
<description>User Last Name</description>
<name>user.name.family</name>
</user-attribute>
<user-attribute>
<description>User eMail</description>
<name>user.home-info.online.email</name>
</user-attribute>


</portlet-app>



And the code snippet I am using to read the User's email :


<portlet:defineObjects />

<%
Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);
String emailID = "init@notworking.com";
if(userInfo!=null){
emailID = (String) userInfo.get("user.home-info.online.email");
System.out.println("Email ID:"+ emailID);
}


I always get userInfo variable as a null emoticon

Can you guide me ?
It took me a few minutes to see the problem myself, but once you realize that "request" is not a PortletRequest it's quite obvious. You need to get the USER_INFO from a PortletRequest, in this case it would be from the "RenderRequest" which is automatically added to the page scope by <portlet:defineObjects />.

So change the line to:

Map userInfo = (Map) renderRequest.getAttribute(PortletRequest.USER_INFO);

and it will work.
Sir, you are awesome ! Thank you emoticon
Thank you! I'm glad to help.
Quick question: How can I access the user's additional email address (under profile) and custom fields ?
hello ray... i got dis error while runnig my jsp


org.apache.jasper.JasperException: An exception occurred processing JSP page /user.jsp at line 8

5:
6: <portlet:defineObjects />
7: <%
8: Map userInfo = (Map)renderRequest.getAttribute(PortletRequest.USER_INFO);
9: String emailID = "init@notworking.com";
10: if(userInfo!=null){
11: emailID = (String) userInfo.get("user.home-info.online.email");


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
com.liferay.portal.kernel.servlet.PortalClassLoaderFilter.doFilter(PortalClassLoaderFilter.java:53)
com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:126)
com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
com.liferay.portal.kernel.servlet.PortalClassLoaderFilter.doFilter(PortalClassLoaderFilter.java:53)
com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilte
You aren't accessing the jsp through a portlet, so it won't work. You can't arbitrarily hit a jsp in a portlet and have it work as if through the portal.
And the code snippet I am using to read the User's email :


<portlet:defineObjects />

<%
Map userInfo = (Map) request.getAttribute(PortletRequest.USER_INFO);
String emailID = "init@notworking.com";
if(userInfo!=null){
emailID = (String) userInfo.get("user.home-info.online.email");
System.out.println("Email ID:"+ emailID);
}%>

<%=emailID%> with this code(with out render ) im getting "init@notworking.com" if i use renderRequest... im getting apache error.. plz guide me.
i want to dispaly the current user id who is accessing the portlet in liferay 6.0.5. ..this is my requirement.. i created a simple jsp portlet.. and installd it in to liferay portal.. help me plz
yes mr. ray i got user id and email... itz only show ing in view.jsp... links are not woking in dat page..but i want to get user id in my index page is it possible? because i need to save the email in to mysql database.. is it possible?