legacy-knowledge-base
公開されました Sep. 10, 2025

ポートレット セッションの属性がテーマから見つかりません

written-by

Ricardo Couso

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

問題

  • 次のように、ポートレットのセッションで属性を設定します。
    @Override
    public void render(
            RenderRequest renderRequest, RenderResponse renderResponse)
        throws IOException, PortletException {
    
        HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(renderRequest);
        HttpSession httpSession = httpServletRequest.getSession();
        httpSession.setAttribute("myAttributeKey", "myAttributeValue");
        
        super.render(renderRequest, renderResponse);
    }
  • 次のように、カスタム テーマの portal_normal.ftl (またはその他のテンプレート) で値 "myAttributeValue" を復元してみてください。
    ${(request.session.getAttribute("myAttributeKey"))!"null"}
  • ポートレットがデプロイされているページでテーマがレンダリングされると、値が見つかりません (したがって null が出力されます)。
  • すべての属性を一覧表示すると、長いプレフィックスを持つ属性キーが表示されます。
    equinox.http.${my-portlet-package-name}myAttributeKey

Environment

  • ライフレイDXP 7.3、7.4

解決策

  • ほとんどの場合、接頭辞は equinox.http です。${my-portlet-package-name} は、属性の設定および取得時にシームレスに追加および削除されます。
  • この状況でもこの動作を行う 1 つの方法は、次のように、ポートレットで元のサーブレット リクエストを使用することです。
    HttpServletRequest httpServletRequest = PortalUtil.getHttpServletRequest(renderRequest);
    HttpServletRequest originalServletRequest = PortalUtil.getOriginalServletRequest(httpServletRequest);
    HttpSession httpSession = originalServletRequest.getSession();
    httpSession.setAttribute("myAttributeKey", "myAttributeValue");
did-this-article-resolve-your-issue

legacy-knowledge-base