Index: core/src/main/java/org/icefaces/impl/context/DOMPartialViewContext.java =================================================================== --- core/src/main/java/org/icefaces/impl/context/DOMPartialViewContext.java (revision 24011) +++ core/src/main/java/org/icefaces/impl/context/DOMPartialViewContext.java (working copy) @@ -21,6 +21,7 @@ package org.icefaces.impl.context; +import org.icefaces.impl.renderkit.DOMRenderKit; import org.icefaces.impl.util.DOMUtils; import org.icefaces.util.EnvUtils; import org.icefaces.util.FocusController; @@ -43,6 +44,8 @@ import javax.faces.context.PartialViewContextWrapper; import javax.faces.context.ResponseWriter; import javax.faces.event.PhaseId; +import javax.faces.render.RenderKit; +import javax.faces.render.RenderKitWrapper; import java.io.IOException; import java.io.Writer; import java.util.ArrayList; @@ -102,11 +105,18 @@ if (null == partialWriter) { try { //TODO: need to revisit the strategy for getting the "raw" output writer directly - Writer outputWriter = getResponseOutputWriter(); - ResponseWriter basicWriter = new BasicResponseWriter(outputWriter, - defaultWriter.getCharacterEncoding(), - defaultWriter.getContentType()); - partialWriter = new PartialResponseWriter(basicWriter); + String contentType = defaultWriter.getContentType(); + String characterEncoding = defaultWriter.getCharacterEncoding(); + Writer outputWriter = getResponseOutputWriter(contentType, characterEncoding); + ResponseWriter responseWriter = null; + if (outputWriter instanceof ResponseWriter) { + responseWriter = (ResponseWriter) outputWriter; + } + else { + responseWriter = new BasicResponseWriter(outputWriter, + characterEncoding, contentType); + } + partialWriter = new PartialResponseWriter(responseWriter); } catch (Exception e) { e.printStackTrace(); } @@ -128,7 +138,9 @@ ExternalContext ec = facesContext.getExternalContext(); //TODO: need to revisit the strategy for getting the "raw" output writer directly - Writer outputWriter = getResponseOutputWriter(); + String contentType = partialWriter.getContentType(); + String characterEncoding = partialWriter.getCharacterEncoding(); + Writer outputWriter = getResponseOutputWriter(contentType, characterEncoding); ec.setResponseContentType("text/xml"); ec.addResponseHeader("Cache-Control", "no-cache"); @@ -212,8 +224,38 @@ } } - protected Writer getResponseOutputWriter() throws IOException { - return facesContext.getExternalContext().getResponseOutputWriter(); + + /** + * The purpose of this method is to return a {@link Writer} that has the ability of writing directly + * or indirectly to the response. It first tries to find the ICEfaces DOMRenderKit under the + * assumption that since it wraps another HTML RenderKit, it inherently wraps another {@link ResponseWriter}. + * This is indeed the case with the PortletFaces Bridge -- in the RenderKit chain-of-responsibility, the + * bridge has it's own HTML RenderKit so that it can filter the response with its own ResponseWriter. + */ + protected Writer getResponseOutputWriter(String contentType, String characterEncoding) throws IOException { + + Writer responseOutputWriter = null; + Writer directResponseOutputWriter = facesContext.getExternalContext().getResponseOutputWriter(); + RenderKit renderKit = facesContext.getRenderKit(); + while (responseOutputWriter == null) { + + if (renderKit instanceof DOMRenderKit) { + DOMRenderKit domRenderKit = (DOMRenderKit) renderKit; + RenderKit wrappedRenderKit = domRenderKit.getWrapped(); + responseOutputWriter = wrappedRenderKit.createResponseWriter(directResponseOutputWriter, contentType, characterEncoding); + } + + else { + if (renderKit instanceof RenderKitWrapper) { + RenderKitWrapper renderKitWrapper = (RenderKitWrapper) renderKit; + renderKit = renderKitWrapper.getWrapped(); + } + else { + responseOutputWriter = directResponseOutputWriter; + } + } + } + return responseOutputWriter; } private void writeXMLPreamble(Writer writer) throws IOException {