use of org.apache.myfaces.renderkit.LazyRenderKit 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);
}
}
Aggregations