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