Search in sources :

Example 1 with Renderer

use of org.apache.myfaces.config.element.Renderer 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 2 with Renderer

use of org.apache.myfaces.config.element.Renderer in project myfaces by apache.

the class FaceletMultipleRequestsTestCase method setupRenderers.

/**
 * Override this methods and add just what it is necessary
 * reduce execution time.
 */
protected void setupRenderers() throws Exception {
    loadStandardFacesConfig();
    for (Renderer element : dispenser.getRenderers(RenderKitFactory.HTML_BASIC_RENDER_KIT)) {
        jakarta.faces.render.Renderer renderer;
        try {
            renderer = (jakarta.faces.render.Renderer) ClassUtils.newInstance(element.getRendererClass());
        } catch (Throwable e) {
            // ignore the failure so that the render kit is configured
            continue;
        }
        renderKit.addRenderer(element.getComponentFamily(), element.getRendererType(), renderer);
    }
    for (ClientBehaviorRenderer element : dispenser.getClientBehaviorRenderers(RenderKitFactory.HTML_BASIC_RENDER_KIT)) {
        jakarta.faces.render.ClientBehaviorRenderer renderer;
        try {
            renderer = (jakarta.faces.render.ClientBehaviorRenderer) ClassUtils.newInstance(element.getRendererClass());
        } catch (Throwable e) {
            // ignore the failure so that the render kit is configured
            continue;
        }
        renderKit.addClientBehaviorRenderer(element.getRendererType(), renderer);
    }
}
Also used : ClientBehaviorRenderer(org.apache.myfaces.config.element.ClientBehaviorRenderer) Renderer(org.apache.myfaces.config.element.Renderer) ClientBehaviorRenderer(org.apache.myfaces.config.element.ClientBehaviorRenderer)

Example 3 with Renderer

use of org.apache.myfaces.config.element.Renderer in project myfaces by apache.

the class FaceletTestCase method setupRenderers.

/**
 * Override this methods and add just what it is necessary
 * reduce execution time.
 */
protected void setupRenderers() throws Exception {
    loadStandardFacesConfig();
    for (Renderer element : dispenser.getRenderers(RenderKitFactory.HTML_BASIC_RENDER_KIT)) {
        jakarta.faces.render.Renderer renderer;
        try {
            renderer = (jakarta.faces.render.Renderer) ClassUtils.newInstance(element.getRendererClass());
        } catch (Throwable e) {
            // ignore the failure so that the render kit is configured
            continue;
        }
        renderKit.addRenderer(element.getComponentFamily(), element.getRendererType(), renderer);
    }
    for (ClientBehaviorRenderer element : dispenser.getClientBehaviorRenderers(RenderKitFactory.HTML_BASIC_RENDER_KIT)) {
        jakarta.faces.render.ClientBehaviorRenderer renderer;
        try {
            renderer = (jakarta.faces.render.ClientBehaviorRenderer) ClassUtils.newInstance(element.getRendererClass());
        } catch (Throwable e) {
            // ignore the failure so that the render kit is configured
            continue;
        }
        renderKit.addClientBehaviorRenderer(element.getRendererType(), renderer);
    }
}
Also used : ClientBehaviorRenderer(org.apache.myfaces.config.element.ClientBehaviorRenderer) Renderer(org.apache.myfaces.config.element.Renderer) ClientBehaviorRenderer(org.apache.myfaces.config.element.ClientBehaviorRenderer)

Aggregations

ClientBehaviorRenderer (org.apache.myfaces.config.element.ClientBehaviorRenderer)3 Renderer (org.apache.myfaces.config.element.Renderer)3 RenderKit (jakarta.faces.render.RenderKit)1 RenderKitFactory (jakarta.faces.render.RenderKitFactory)1 FacesConfigData (org.apache.myfaces.config.element.FacesConfigData)1 LazyRenderKit (org.apache.myfaces.renderkit.LazyRenderKit)1