【问题标题】:Remove session attribute when opening Facelets page打开 Facelets 页面时删除会话属性
【发布时间】:2012-07-06 18:19:26
【问题描述】:

我正在从 servlet 过滤器向 Facelets 页面返回一条消息。为了将消息从 servlet 过滤器传输到 Facelets 页面,我使用了一个会话变量。显示消息后,我想删除会话变量。如何做到这一点? 还有另一种将数据从 servlet 传递到 Facelets 的方法吗?

【问题讨论】:

    标签: jsf-2 session-variables servlet-filters


    【解决方案1】:

    RENDER_RESPONSE 的后期删除它。您可以为此使用<f:view afterPhase>

    <f:view afterPhase="#{bean.removeSessionAttributeAfterRender}">
    

    public void removeSessionAttributeAfterRender(PhaseEvent event) {
        if (event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
            FacesContext.getCurrentInstance().getExternalContext()
                .getSessionMap().remove("sessionAttributeName");
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多