Search in sources :

Example 1 with ClientBehaviorRenderer

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

the class ClientBehaviorBase method getScript.

/**
 * {@inheritDoc}
 */
@Override
public String getScript(ClientBehaviorContext behaviorContext) {
    Assert.notNull(behaviorContext, "behaviorContext");
    ClientBehaviorRenderer renderer = getRenderer(behaviorContext.getFacesContext());
    if (renderer != null) {
        // to the BehaviorRenderer.getScript method.
        try {
            setCachedFacesContext(behaviorContext.getFacesContext());
            return renderer.getScript(behaviorContext, this);
        } finally {
            setCachedFacesContext(null);
        }
    }
    // Otherwise, this method returns null.
    return null;
}
Also used : ClientBehaviorRenderer(jakarta.faces.render.ClientBehaviorRenderer)

Example 2 with ClientBehaviorRenderer

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

the class ClientBehaviorBase method decode.

/**
 * {@inheritDoc}
 */
@Override
public void decode(FacesContext context, UIComponent component) {
    Assert.notNull(context, "context");
    Assert.notNull(component, "component");
    // If a BehaviorRenderer is available for the specified behavior renderer type, this method delegates
    // to the BehaviorRenderer's decode() method. Otherwise, no decoding is performed.
    ClientBehaviorRenderer renderer = getRenderer(context);
    if (renderer != null) {
        renderer.decode(context, component, this);
    }
}
Also used : ClientBehaviorRenderer(jakarta.faces.render.ClientBehaviorRenderer)

Example 3 with ClientBehaviorRenderer

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

the class ApplicationImpl method createBehavior.

@Override
public Behavior createBehavior(String behaviorId) throws FacesException {
    Assert.notEmpty(behaviorId, "behaviorId");
    final Class<? extends Behavior> behaviorClass = getObjectFromClassMap(behaviorId, _behaviorClassMap);
    if (behaviorClass == null) {
        throw new FacesException("Could not find any registered behavior-class for behaviorId : " + behaviorId);
    }
    try {
        if (!_cdiManagedBehaviorMap.containsKey(behaviorClass)) {
            FacesBehavior annotation = behaviorClass.getAnnotation(FacesBehavior.class);
            if (annotation != null && annotation.managed()) {
                _cdiManagedBehaviorMap.put(behaviorClass, true);
            } else {
                _cdiManagedBehaviorMap.put(behaviorClass, false);
            }
        }
        boolean managed = _cdiManagedBehaviorMap.get(behaviorClass);
        Behavior behavior = null;
        if (managed) {
            if (ClientBehavior.class.isAssignableFrom(behaviorClass)) {
                behavior = new FacesClientBehaviorCDIWrapper((Class<ClientBehavior>) behaviorClass, behaviorId);
            } else {
                behavior = new FacesBehaviorCDIWrapper(behaviorClass, behaviorId);
            }
            Behavior innerBehavior = ((FacesWrapper<Behavior>) behavior).getWrapped();
            FacesContext facesContext = getFacesContext();
            _handleAttachedResourceDependencyAnnotations(facesContext, innerBehavior);
            if (innerBehavior instanceof ClientBehaviorBase) {
                ClientBehaviorBase clientBehavior = (ClientBehaviorBase) innerBehavior;
                String renderType = clientBehavior.getRendererType();
                if (renderType != null) {
                    ClientBehaviorRenderer cbr = facesContext.getRenderKit().getClientBehaviorRenderer(renderType);
                    _handleAttachedResourceDependencyAnnotations(facesContext, cbr);
                }
            }
        } else {
            behavior = behaviorClass.newInstance();
            FacesContext facesContext = getFacesContext();
            _handleAttachedResourceDependencyAnnotations(facesContext, behavior);
            if (behavior instanceof ClientBehaviorBase) {
                ClientBehaviorBase clientBehavior = (ClientBehaviorBase) behavior;
                String renderType = clientBehavior.getRendererType();
                if (renderType != null) {
                    ClientBehaviorRenderer cbr = facesContext.getRenderKit().getClientBehaviorRenderer(renderType);
                    _handleAttachedResourceDependencyAnnotations(facesContext, cbr);
                }
            }
        }
        return behavior;
    } catch (Exception e) {
        log.log(Level.SEVERE, "Could not instantiate behavior " + behaviorClass, e);
        throw new FacesException("Could not instantiate behavior: " + behaviorClass, e);
    }
}
Also used : FacesContext(jakarta.faces.context.FacesContext) FacesBehaviorCDIWrapper(org.apache.myfaces.cdi.wrapper.FacesBehaviorCDIWrapper) FacesWrapper(jakarta.faces.FacesWrapper) FacesException(jakarta.faces.FacesException) MissingResourceException(java.util.MissingResourceException) NamingException(javax.naming.NamingException) ELException(jakarta.el.ELException) FacesException(jakarta.faces.FacesException) ClientBehaviorRenderer(jakarta.faces.render.ClientBehaviorRenderer) ClientBehaviorBase(jakarta.faces.component.behavior.ClientBehaviorBase) FacesClientBehaviorCDIWrapper(org.apache.myfaces.cdi.wrapper.FacesClientBehaviorCDIWrapper) ClientBehavior(jakarta.faces.component.behavior.ClientBehavior) FacesBehavior(jakarta.faces.component.behavior.FacesBehavior) Behavior(jakarta.faces.component.behavior.Behavior) FacesBehavior(jakarta.faces.component.behavior.FacesBehavior)

Example 4 with ClientBehaviorRenderer

use of jakarta.faces.render.ClientBehaviorRenderer in project myfaces-tobago by apache.

the class RendererBase method getCommandMap.

private static CommandMap getCommandMap(final FacesContext facesContext, final ClientBehaviorContext clientBehaviorContext, final ClientBehavior clientBehavior) {
    if (clientBehavior instanceof ClientBehaviorBase) {
        String type = ((ClientBehaviorBase) clientBehavior).getRendererType();
        // this is to use a different renderer for Tobago components and other components.
        if (type.equals(AjaxBehavior.BEHAVIOR_ID)) {
            type = "org.apache.myfaces.tobago.behavior.Ajax";
        }
        final ClientBehaviorRenderer renderer = facesContext.getRenderKit().getClientBehaviorRenderer(type);
        final String dummy = renderer.getScript(clientBehaviorContext, clientBehavior);
        if (dummy != null) {
            return CommandMap.restoreCommandMap(facesContext);
        }
    } else {
        LOG.warn("Ignoring: '{}'", clientBehavior);
    }
    return null;
}
Also used : TobagoClientBehaviorRenderer(org.apache.myfaces.tobago.internal.renderkit.renderer.TobagoClientBehaviorRenderer) ClientBehaviorRenderer(jakarta.faces.render.ClientBehaviorRenderer) ClientBehaviorBase(jakarta.faces.component.behavior.ClientBehaviorBase)

Example 5 with ClientBehaviorRenderer

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

ClientBehaviorRenderer (jakarta.faces.render.ClientBehaviorRenderer)13 RenderKit (jakarta.faces.render.RenderKit)5 ClientBehaviorBase (jakarta.faces.component.behavior.ClientBehaviorBase)4 PrintWriter (java.io.PrintWriter)3 FacesException (jakarta.faces.FacesException)2 ClientBehavior (jakarta.faces.component.behavior.ClientBehavior)2 FacesContext (jakarta.faces.context.FacesContext)2 TobagoClientBehaviorRenderer (org.apache.myfaces.tobago.internal.renderkit.renderer.TobagoClientBehaviorRenderer)2 MessageUtils.getExceptionMessageString (com.sun.faces.util.MessageUtils.getExceptionMessageString)1 ELException (jakarta.el.ELException)1 FacesWrapper (jakarta.faces.FacesWrapper)1 UIComponent (jakarta.faces.component.UIComponent)1 UIForm (jakarta.faces.component.UIForm)1 AjaxBehavior (jakarta.faces.component.behavior.AjaxBehavior)1 Behavior (jakarta.faces.component.behavior.Behavior)1 FacesBehavior (jakarta.faces.component.behavior.FacesBehavior)1 FacesBehaviorRenderer (jakarta.faces.render.FacesBehaviorRenderer)1 FacesRenderer (jakarta.faces.render.FacesRenderer)1 RenderKitFactory (jakarta.faces.render.RenderKitFactory)1 Annotation (java.lang.annotation.Annotation)1