The error occurs because of an attempt to render your response during the JSF render phase.
You are using a raw response object obtained via ExternalContext
, and writing the response yourself. You must tell the JSF runtime that the response is complete so it doesn't attempt to process it.
Save a reference to your FacesContext
:
FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) ctx.getExternalContext().getResponse();
...
and call responseComplete()
when you finish building your response:
ctx.responseComplete();