Search in sources :

Example 1 with PartialResponseWriterImpl

use of org.apache.myfaces.context.PartialResponseWriterImpl in project myfaces by apache.

the class PartialViewContextImpl method getPartialResponseWriter.

@Override
public PartialResponseWriter getPartialResponseWriter() {
    assertNotReleased();
    if (_partialResponseWriter == null) {
        ResponseWriter responseWriter = context.getResponseWriter();
        if (responseWriter == null) {
            // ResponseWriter from the RenderKit and then wrap if necessary.
            try {
                RenderKit renderKit = context.getRenderKit();
                if (renderKit == null) {
                    // If the viewRoot was set to null by some reason, or there is no
                    // renderKitId on that view, this could be still an ajax redirect,
                    // so we have to try to calculate the renderKitId and return a
                    // RenderKit instance, to send the response.
                    String renderKitId = context.getApplication().getViewHandler().calculateRenderKitId(context);
                    RenderKitFactory rkf = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
                    renderKit = rkf.getRenderKit(context, renderKitId);
                }
                responseWriter = renderKit.createResponseWriter(context.getExternalContext().getResponseOutputWriter(), "text/xml", context.getExternalContext().getRequestCharacterEncoding());
            } catch (IOException e) {
                throw new IllegalStateException("Cannot create Partial Response Writer", e);
            }
        }
        // createResponseWriter,  so we should cast here for it and prevent double wrapping.
        if (responseWriter instanceof PartialResponseWriter) {
            _partialResponseWriter = (PartialResponseWriter) responseWriter;
        } else {
            _partialResponseWriter = new PartialResponseWriterImpl(responseWriter);
        }
    }
    return _partialResponseWriter;
}
Also used : PartialResponseWriterImpl(org.apache.myfaces.context.PartialResponseWriterImpl) ResponseWriter(jakarta.faces.context.ResponseWriter) PartialResponseWriter(jakarta.faces.context.PartialResponseWriter) RenderKit(jakarta.faces.render.RenderKit) PartialResponseWriter(jakarta.faces.context.PartialResponseWriter) IOException(java.io.IOException) RenderKitFactory(jakarta.faces.render.RenderKitFactory)

Aggregations

PartialResponseWriter (jakarta.faces.context.PartialResponseWriter)1 ResponseWriter (jakarta.faces.context.ResponseWriter)1 RenderKit (jakarta.faces.render.RenderKit)1 RenderKitFactory (jakarta.faces.render.RenderKitFactory)1 IOException (java.io.IOException)1 PartialResponseWriterImpl (org.apache.myfaces.context.PartialResponseWriterImpl)1