ad-inf
ad-inf

Reputation: 1570

Remove session attribute when opening Facelets page

I am returning a message from servlet filter to a Facelets page. To transfer the message from servlet filter to Facelets page, I am using a session variable. After the message is displayed, I would like to remove the session variable. How this can be achieved? Also is there an alternate way to pass data from servlet to Facelets?

Upvotes: 2

Views: 2597

Answers (1)

BalusC
BalusC

Reputation: 1108632

Remove it during the afterphase of RENDER_RESPONSE. You could use <f:view afterPhase> for this.

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

with

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

Upvotes: 5

Related Questions