legacy-knowledge-base
公開されました Jul. 2, 2025

user-portrait taglibのオーバーライド時にUserオブジェクトにアクセスする方法

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

問題

  • Liferay Portal 6.x では、現在のユーザーの画像を画面に表示するために、 user-display taglib を利用していました。 しかし、Liferay DXP 7.x では、 user-portrait taglib を使用しています。これは、オーバーライドされるのを助けるために、実際に page.jsp.readme ファイルを含みます。 このタグリブのUserオブジェクトにアクセスして、ユーザーの情報を取得するにはどうすればよいでしょうか?

Environment

  • Liferay DXP(バージョン不問)

解決策

  • Liferay DXPでは、セキュリティとパフォーマンスの理由により、その情報にアクセスする方法が変更されています。 ユーザー情報を取得するためには、 page.jsp.readme ファイルをリネームし、 .readme サフィックスを削除して、以下のコードを追加します:
<%@ 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");
%>
  • そこで、userDisplayの情報にアクセスし、操作することができます。
did-this-article-resolve-your-issue

legacy-knowledge-base