I have a legacy application using JSF version 1.1
I am trying to set a cookie in all responses, but through a PhaseListener
implementation instead of usual Filter
because of specific requirement.
I did something like:
public class MyPhaseListener implements PhaseListener {
public PhaseId getPhaseId() {
return PhaseId.ANY_PHASE;
}
public void beforePhase(PhaseEvent event) {
}
public void afterPhase(PhaseEvent event) {
if (event.getPhaseId() == PhaseId.RENDER_RESPONSE) {
HttpServletResponse httpResponse = (HttpServletResponse) FacesContext
.getCurrentInstance().getExternalContext().getResponse();
int cookieValue = 100;
Cookie cookie = new Cookie("myCookie", "" + cookieValue);
cookie.setPath("/");
httpResponse.addCookie(cookie);
}
}
}
However, when I am checking the responses in chrome dev console, I do not see this cookie.
What am I doing wrong?