myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Poecher <>
Subject Re: Facelets Back Button
Date Thu, 20 Nov 2008 16:06:41 GMT

Vinaya Tirikkovalluru wrote:
> Hi,
> I recently switched over to facelets.
> Now all my jsps are xhtmls
> How do I expire the page if the user clicks on browser back button?
> Any ideas?

Hi Vinaya,

I just did it via a Phase Listener. This would work on all JSF
implementations. The problem is though that due to a bug Firefox 3.0.x
ignore the cache settings. I saw that they consider it a major bug and they
also have a patch read with the last modified date of yesterday. 

Here is the code:

import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

public class NoBrowserCachePhaseListener implements PhaseListener {
	public void afterPhase(PhaseEvent event) {
		// Do nothing special

	public void beforePhase(PhaseEvent event) {
		FacesContext facesContext = event.getFacesContext();
		HttpServletResponse response = (HttpServletResponse)
		response.addHeader("Pragma", "no-cache");
		response.addHeader("Cache-Control", "no-cache");
		response.addHeader("Cache-Control", "no-store");
		response.addHeader("Cache-Control", "must-revalidate");
		response.addHeader("Expires", "0"); 

	public PhaseId getPhaseId() {
		return PhaseId.RENDER_RESPONSE;

You need to add this to your faces-config.xml:


View this message in context:
Sent from the MyFaces - Users mailing list archive at

View raw message