use of jakarta.faces.component.behavior.Behavior 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.Behavior in project myfaces by apache.
the class UIComponentBase method broadcast.
/**
* Invoke any listeners attached to this object which are listening for an event whose type matches the specified
* event's runtime type.
* <p>
* This method does not propagate the event up to parent components, ie listeners attached to parent components
* don't automatically get called.
* <p>
* If any of the listeners throws AbortProcessingException then that exception will prevent any further listener
* callbacks from occurring, and the exception propagates out of this method without alteration.
* <p>
* ActionEvent events are typically queued by the renderer associated with this component in its decode method;
* ValueChangeEvent events by the component's validate method. In either case the event's source property references
* a component. At some later time the UIViewRoot component iterates over its queued events and invokes the
* broadcast method on each event's source object.
*
* @param event
* must not be null.
*/
@Override
public void broadcast(FacesEvent event) throws AbortProcessingException {
Assert.notNull(event, "event");
if (event instanceof BehaviorEvent && event.getComponent() == this) {
Behavior behavior = ((BehaviorEvent) event).getBehavior();
behavior.broadcast((BehaviorEvent) event);
}
if (_facesListeners == null) {
return;
}
// perf: _facesListeners is RandomAccess instance (jakarta.faces.component._DeltaList)
for (int i = 0, size = _facesListeners.size(); i < size; i++) {
FacesListener facesListener = _facesListeners.get(i);
if (event.isAppropriateListener(facesListener)) {
event.processListener(facesListener);
}
}
}
use of jakarta.faces.component.behavior.Behavior in project mojarra by eclipse-ee4j.
the class UIComponentBase method broadcast.
// -------------------------------------------- Lifecycle Processing Methods
/**
* @throws AbortProcessingException {@inheritDoc}
* @throws IllegalStateException {@inheritDoc}
* @throws NullPointerException {@inheritDoc}
*/
@Override
public void broadcast(FacesEvent event) throws AbortProcessingException {
if (event == null) {
throw new NullPointerException();
}
if (event instanceof BehaviorEvent) {
BehaviorEvent behaviorEvent = (BehaviorEvent) event;
Behavior behavior = behaviorEvent.getBehavior();
behavior.broadcast(behaviorEvent);
}
if (listeners == null) {
return;
}
for (FacesListener listener : listeners.asArray(FacesListener.class)) {
if (event.isAppropriateListener(listener)) {
event.processListener(listener);
}
}
}
use of jakarta.faces.component.behavior.Behavior in project myfaces by apache.
the class BehaviorTagHandlerDelegate method applyAttachedObject.
/**
* Create a ClientBehavior and attach it to the component
*/
@Override
public void applyAttachedObject(FacesContext context, UIComponent parent) {
// Retrieve the current FaceletContext from FacesContext object
FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
ValueExpression ve = null;
Behavior behavior = null;
if (_delegate.getBinding() != null) {
ve = _delegate.getBinding().getValueExpression(faceletContext, Behavior.class);
behavior = (Behavior) ve.getValue(faceletContext);
}
if (behavior == null) {
behavior = this.createBehavior(faceletContext);
if (ve != null) {
ve.setValue(faceletContext, behavior);
}
}
if (behavior == null) {
throw new TagException(_delegate.getTag(), "No Validator was created");
}
_delegate.setAttributes(faceletContext, behavior);
if (behavior instanceof ClientBehavior) {
// cast to a ClientBehaviorHolder
ClientBehaviorHolder cvh = (ClientBehaviorHolder) parent;
// TODO: check if the behavior could be applied to the current parent
// For run tests it is not necessary, so we let this one pending.
// It is necessary to obtain a event name for add it, so we have to
// look first to the defined event name, otherwise take the default from
// the holder
String eventName = getEventName();
if (eventName == null) {
eventName = cvh.getDefaultEventName();
}
if (eventName == null) {
throw new TagAttributeException(_delegate.getEvent(), "eventName could not be defined for client behavior " + behavior.toString());
} else if (!cvh.getEventNames().contains(eventName)) {
throw new TagAttributeException(_delegate.getEvent(), "eventName " + eventName + " not found on component instance");
} else {
cvh.addClientBehavior(eventName, (ClientBehavior) behavior);
}
AjaxHandler.registerFacesJsResource(faceletContext, parent);
}
}
use of jakarta.faces.component.behavior.Behavior in project myfaces by apache.
the class MockApplication20 method createBehavior.
public Behavior createBehavior(String behaviorId) throws FacesException {
checkNull(behaviorId, "behaviorId");
checkEmpty(behaviorId, "behaviorId");
final Class<?> behaviorClass = this._behaviorClassMap.get(behaviorId);
if (behaviorClass == null) {
throw new FacesException("Could not find any registered behavior-class for behaviorId : " + behaviorId);
}
try {
final Behavior behavior = (Behavior) behaviorClass.newInstance();
_handleAttachedResourceDependencyAnnotations(FacesContext.getCurrentInstance(), behaviorClass);
return behavior;
} catch (Exception e) {
throw new FacesException("Could not instantiate behavior: " + behaviorClass, e);
}
}
Aggregations