Search in sources :

Example 1 with RenderKitFactory

use of jakarta.faces.render.RenderKitFactory 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)

Example 2 with RenderKitFactory

use of jakarta.faces.render.RenderKitFactory in project myfaces by apache.

the class FacesConfigurator method configureRenderKits.

private void configureRenderKits() {
    RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
    FacesConfigData dispenser = getDispenser();
    for (String renderKitId : dispenser.getRenderKitIds()) {
        Collection<String> renderKitClass = dispenser.getRenderKitClasses(renderKitId);
        if (renderKitClass.isEmpty()) {
            renderKitClass = new ArrayList<>(1);
            renderKitClass.add(DEFAULT_RENDER_KIT_CLASS);
        }
        RenderKit renderKit = (RenderKit) ClassUtils.buildApplicationObject(RenderKit.class, renderKitClass, null);
        // If the default html RenderKit instance is wrapped, the top level object will not implement
        // LazyRenderKit and all renderers will be added using the standard form.
        boolean lazyRenderKit = renderKit instanceof LazyRenderKit;
        for (Renderer element : dispenser.getRenderers(renderKitId)) {
            jakarta.faces.render.Renderer renderer;
            if (element.getRendererClass() != null) {
                if (lazyRenderKit) {
                    // Add renderer using LazyRenderKit interface. This will have the effect of improve startup
                    // time avoiding load renderer classes that are not used.
                    ((LazyRenderKit) renderKit).addRenderer(element.getComponentFamily(), element.getRendererType(), element.getRendererClass());
                } else {
                    // Use standard form
                    try {
                        renderer = (jakarta.faces.render.Renderer) ClassUtils.newInstance(element.getRendererClass());
                    } catch (Throwable e) {
                        // ignore the failure so that the render kit is configured
                        log.log(Level.SEVERE, "failed to configure class " + element.getRendererClass(), e);
                        continue;
                    }
                    if (renderer != null) {
                        renderKit.addRenderer(element.getComponentFamily(), element.getRendererType(), renderer);
                    } else {
                        log.log(Level.INFO, "Renderer instance cannot be created for " + element.getRendererClass() + ", ignoring..." + element.getRendererClass());
                    }
                }
            } else {
                log.log(Level.INFO, "Renderer element with no rendererClass found, ignoring..." + element.getRendererClass());
            }
        }
        Collection<ClientBehaviorRenderer> clientBehaviorRenderers = dispenser.getClientBehaviorRenderers(renderKitId);
        for (ClientBehaviorRenderer clientBehaviorRenderer : clientBehaviorRenderers) {
            try {
                jakarta.faces.render.ClientBehaviorRenderer behaviorRenderer = (jakarta.faces.render.ClientBehaviorRenderer) ClassUtils.newInstance(clientBehaviorRenderer.getRendererClass());
                renderKit.addClientBehaviorRenderer(clientBehaviorRenderer.getRendererType(), behaviorRenderer);
            } catch (Throwable e) {
                if (log.isLoggable(Level.SEVERE)) {
                    log.log(Level.SEVERE, "failed to configure client behavior renderer class " + clientBehaviorRenderer.getRendererClass(), e);
                }
            }
        }
        renderKitFactory.addRenderKit(renderKitId, renderKit);
    }
}
Also used : FacesConfigData(org.apache.myfaces.config.element.FacesConfigData) LazyRenderKit(org.apache.myfaces.renderkit.LazyRenderKit) ClientBehaviorRenderer(org.apache.myfaces.config.element.ClientBehaviorRenderer) LazyRenderKit(org.apache.myfaces.renderkit.LazyRenderKit) RenderKit(jakarta.faces.render.RenderKit) Renderer(org.apache.myfaces.config.element.Renderer) ClientBehaviorRenderer(org.apache.myfaces.config.element.ClientBehaviorRenderer) RenderKitFactory(jakarta.faces.render.RenderKitFactory)

Example 3 with RenderKitFactory

use of jakarta.faces.render.RenderKitFactory in project myfaces by apache.

the class AbstractJsfTestCase method setUpRenderKit.

/**
 * Setup the <code>renderKit</code> variable. This is a good place to use
 * <code>ConfigParser</code> to register converters, validators, components
 * or renderkits.
 *
 * @throws Exception
 */
protected void setUpRenderKit() throws Exception {
    RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
    renderKit = new MockRenderKit();
    renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit);
}
Also used : MockRenderKit(org.apache.myfaces.test.mock.MockRenderKit) RenderKitFactory(jakarta.faces.render.RenderKitFactory)

Example 4 with RenderKitFactory

use of jakarta.faces.render.RenderKitFactory in project myfaces by apache.

the class ApplicationImplAnnotationTest method setUpRenderKit.

@Override
protected void setUpRenderKit() throws Exception {
    RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
    renderKit = new MockRenderKit();
    renderKit.addRenderer("jakarta.faces.Output", "jakarta.faces.resource.Script", new HtmlScriptRenderer());
    renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit);
}
Also used : HtmlScriptRenderer(org.apache.myfaces.renderkit.html.HtmlScriptRenderer) MockRenderKit(org.apache.myfaces.test.mock.MockRenderKit) RenderKitFactory(jakarta.faces.render.RenderKitFactory) MockRenderKitFactory(org.apache.myfaces.test.mock.MockRenderKitFactory)

Example 5 with RenderKitFactory

use of jakarta.faces.render.RenderKitFactory in project myfaces by apache.

the class MockedJsfTestContainer method setUpRenderKit.

/**
 * Setup the <code>renderKit</code> variable. This is a good place to use
 * <code>ConfigParser</code> to register converters, validators, components
 * or renderkits.
 *
 * @throws Exception
 */
protected void setUpRenderKit() {
    RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
    renderKit = new MockRenderKit();
    renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit);
}
Also used : RenderKitFactory(jakarta.faces.render.RenderKitFactory)

Aggregations

RenderKitFactory (jakarta.faces.render.RenderKitFactory)51 RenderKit (jakarta.faces.render.RenderKit)40 PrintWriter (java.io.PrintWriter)23 UIComponent (jakarta.faces.component.UIComponent)14 Renderer (jakarta.faces.render.Renderer)14 UIViewRoot (jakarta.faces.component.UIViewRoot)12 MockRenderKit (com.sun.faces.mock.MockRenderKit)6 FacesContext (jakarta.faces.context.FacesContext)5 MockRenderKit (org.apache.myfaces.test.mock.MockRenderKit)5 ResponseWriter (jakarta.faces.context.ResponseWriter)4 Map (java.util.Map)4 ExternalContext (jakarta.faces.context.ExternalContext)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 FacesException (jakarta.faces.FacesException)2 UIForm (jakarta.faces.component.UIForm)2 UIInput (jakarta.faces.component.UIInput)2 PartialResponseWriter (jakarta.faces.context.PartialResponseWriter)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2