Search in sources :

Example 1 with FacesBehaviorRenderer

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

the class AnnotationConfigurator method handleFacesBehaviorRenderer.

private void handleFacesBehaviorRenderer(FacesConfigImpl facesConfig, Set<Class<?>> classes) {
    for (Class<?> clazz : classes) {
        FacesBehaviorRenderer facesBehaviorRenderer = (FacesBehaviorRenderer) clazz.getAnnotation(FacesBehaviorRenderer.class);
        if (facesBehaviorRenderer != null) {
            String renderKitId = facesBehaviorRenderer.renderKitId();
            if (log.isLoggable(Level.FINEST)) {
                log.finest("addClientBehaviorRenderer(" + renderKitId + ", " + facesBehaviorRenderer.rendererType() + ", " + clazz.getName() + ')');
            }
            org.apache.myfaces.config.impl.element.RenderKitImpl renderKit = (org.apache.myfaces.config.impl.element.RenderKitImpl) facesConfig.getRenderKit(renderKitId);
            if (renderKit == null) {
                renderKit = new org.apache.myfaces.config.impl.element.RenderKitImpl();
                renderKit.setId(renderKitId);
                facesConfig.addRenderKit(renderKit);
            }
            org.apache.myfaces.config.impl.element.ClientBehaviorRendererImpl cbr = new org.apache.myfaces.config.impl.element.ClientBehaviorRendererImpl();
            cbr.setRendererType(facesBehaviorRenderer.rendererType());
            cbr.setRendererClass(clazz.getName());
            renderKit.addClientBehaviorRenderer(cbr);
        }
    }
}
Also used : FacesBehaviorRenderer(jakarta.faces.render.FacesBehaviorRenderer)

Example 2 with FacesBehaviorRenderer

use of jakarta.faces.render.FacesBehaviorRenderer in project mojarra by eclipse-ee4j.

the class RenderKitConfigHandler method push.

/**
 * @see com.sun.faces.application.annotation.ConfigAnnotationHandler#push(jakarta.faces.context.FacesContext)
 */
@Override
public void push(FacesContext ctx) {
    if (annotatedRenderers != null) {
        RenderKitFactory rkf = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
        for (Map.Entry<Class<?>, Annotation> entry : annotatedRenderers.entrySet()) {
            Class<?> rClass = entry.getKey();
            if (entry.getValue() instanceof FacesRenderer) {
                FacesRenderer ra = (FacesRenderer) entry.getValue();
                try {
                    RenderKit rk = rkf.getRenderKit(ctx, ra.renderKitId());
                    if (rk == null) {
                        throw new IllegalStateException("Error processing annotated Renderer " + ra.toString() + " on class " + rClass.getName() + ".  Unable to find specified RenderKit.");
                    }
                    rk.addRenderer(ra.componentFamily(), ra.rendererType(), (Renderer) rClass.newInstance());
                } catch (IllegalStateException | InstantiationException | IllegalAccessException e) {
                    throw new FacesException(e);
                }
            } else if (entry.getValue() instanceof FacesBehaviorRenderer) {
                FacesBehaviorRenderer bra = (FacesBehaviorRenderer) entry.getValue();
                try {
                    RenderKit rk = rkf.getRenderKit(ctx, bra.renderKitId());
                    if (rk == null) {
                        throw new IllegalStateException("Error processing annotated ClientBehaviorRenderer " + bra.toString() + " on class " + rClass.getName() + ".  Unable to find specified RenderKit.");
                    }
                    rk.addClientBehaviorRenderer(bra.rendererType(), (ClientBehaviorRenderer) rClass.newInstance());
                } catch (IllegalStateException | InstantiationException | IllegalAccessException e) {
                    throw new FacesException(e);
                }
            }
        }
    }
}
Also used : FacesBehaviorRenderer(jakarta.faces.render.FacesBehaviorRenderer) Annotation(java.lang.annotation.Annotation) FacesException(jakarta.faces.FacesException) ClientBehaviorRenderer(jakarta.faces.render.ClientBehaviorRenderer) RenderKit(jakarta.faces.render.RenderKit) HashMap(java.util.HashMap) Map(java.util.Map) RenderKitFactory(jakarta.faces.render.RenderKitFactory) FacesRenderer(jakarta.faces.render.FacesRenderer)

Aggregations

FacesBehaviorRenderer (jakarta.faces.render.FacesBehaviorRenderer)2 FacesException (jakarta.faces.FacesException)1 ClientBehaviorRenderer (jakarta.faces.render.ClientBehaviorRenderer)1 FacesRenderer (jakarta.faces.render.FacesRenderer)1 RenderKit (jakarta.faces.render.RenderKit)1 RenderKitFactory (jakarta.faces.render.RenderKitFactory)1 Annotation (java.lang.annotation.Annotation)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1