use of jakarta.faces.component.behavior.FacesBehavior in project myfaces by apache.
the class AnnotationConfigurator method handleFacesBehavior.
private void handleFacesBehavior(FacesConfigImpl facesConfig, Set<Class<?>> classes) {
for (Class<?> clazz : classes) {
FacesBehavior facesBehavior = (FacesBehavior) clazz.getAnnotation(FacesBehavior.class);
if (facesBehavior != null) {
// Can only apply @FacesBehavior to Behavior implementors.
if (!jakarta.faces.component.behavior.Behavior.class.isAssignableFrom(clazz)) {
// Just log this. We'll catch it later in the runtime.
if (log.isLoggable(Level.WARNING)) {
log.warning(clazz.getName() + " is annotated with @jakarta.faces.component.behavior.FacesBehavior, " + "but does not implement jakarta.faces.component.behavior.Behavior");
}
}
if (log.isLoggable(Level.FINEST)) {
log.finest("addBehavior(" + facesBehavior.value() + ", " + clazz.getName() + ')');
}
BehaviorImpl behavior = new BehaviorImpl();
behavior.setBehaviorId(facesBehavior.value());
behavior.setBehaviorClass(clazz.getName());
facesConfig.addBehavior(behavior);
}
}
}
use of jakarta.faces.component.behavior.FacesBehavior 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.component.behavior.FacesBehavior in project mojarra by eclipse-ee4j.
the class CdiUtils method createBehavior.
/**
* Create a behavior using the FacesBehavior value attribute.
*
* @param beanManager the bean manager.
* @param value the value attribute.
* @return the behavior, or null if we could not match one.
*/
public static Behavior createBehavior(BeanManager beanManager, String value) {
Behavior delegatingBehavior = null;
Behavior managedBehavior = getBeanReference(beanManager, Behavior.class, FacesBehavior.Literal.of(value, true));
if (managedBehavior != null) {
delegatingBehavior = new CdiBehavior(value, managedBehavior);
}
return delegatingBehavior;
}
Aggregations