legacy-knowledge-base
Publicado Jul. 25, 0002

How to access User object when overriding user-portrait taglib

written-by

Antonio Ortega

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

legacy-article

learn-legacy-article-disclaimer-text

Issue

  • In Liferay Portal 6.x we made use of user-display taglib in order to show current user's image on screen. However, in Liferay DXP 7.x we are using user-portrait taglib, which actually includes a page.jsp.readme file in order to help being overriden. How can we access User object from this taglib so we can retrieve user's information?

Environment

  • Liferay DXP (Any version)

Resolution

  • Due to security and performance reasons the way to access to that information have been modified in Liferay DXP. In order to retrieve user's information, you can rename page.jsp.readme file removing .readme suffix and adding below code:
<%@ page import="com.liferay.taglib.ui.UserPortraitTag" %>
<%@ page import="com.liferay.portal.kernel.bean.BeanPropertiesUtil" %>
<%@ page import="com.liferay.portal.kernel.model.User" %>

<%
Object userPortraitTag = request.getAttribute(UserPortraitTag.class.getName());

User userDisplay = (User) BeanPropertiesUtil.getObject(userPortraitTag, "user");
%>
  • Once there, you can access userDisplay's information to work with it.
did-this-article-resolve-your-issue

legacy-knowledge-base