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;
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations