Phase listener to set IE to edge or X-UA-Compatible value

//java placed in a java design element


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;

public class UACompatibleHeaderPhaseListener implements PhaseListener {
	private static final long serialVersionUID = 1L;

	// @Override
	public PhaseId getPhaseId() {
		return PhaseId.RENDER_RESPONSE;

	// @Override
	public void beforePhase(PhaseEvent event) {
		try {
			final FacesContext facesContext = event.getFacesContext();
			final HttpServletResponse response = (HttpServletResponse) facesContext
			response.addHeader("X-UA-Compatible", "IE=edge");
		} catch (Exception e) {
			System.out.println("err setting header");

	// @Override
	public void afterPhase(PhaseEvent event) {



//this is put in the Faces config

mark t hughes
November 12, 2012 7:40 AM

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.

2 comment(s)Login first to comment...
Steve Cochrane
(at 09:37 on 21.04.2015)
Why not add the tag to the theme?...

P Solano
(at 07:59 on 17.11.2012)
response.addHeader("X-UA-Compatible", "IE=edge") is not working for me; I had to change it to:
response.setHeader("X-UA-Compatible", "IE=edge");

I'm still running 8.5.2 so I had to add this code under my own Source Folder and added it to Build Path from Package Explorer.
Thanks for this tip.