Edge や X-UA-Compatible の値を IE にセットするフェーズリスナー

//Java設計要素として配置
 
 
package com.refchem.app;
 
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
          .getExternalContext().getResponse();
      response.addHeader("X-UA-Compatible", "IE=edge");
    } catch (Exception e) {
      System.out.println("err setting header");
    }
  }
 
  // @Override
  public void afterPhase(PhaseEvent event) {
 
  }
 
}





//Faces config に次の記述を
<lifecycle>
  <phase-listener>com.refchem.app.UACompatibleHeaderPhaseListener</phase-listener>
</lifecycle>

Java
katoman
August 18, 2015 9:53 AM
Rating
0





No comments yetLogin first to comment...