How to access User object when overriding user-portrait taglib

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.
¿Fue útil este artículo?
Usuarios a los que les pareció útil: 0 de 0