use of javax.faces.view.BehaviorHolderAttachedObjectTarget in project primefaces by primefaces.
the class AbstractBehaviorHandler method apply.
@Override
public void apply(FaceletContext faceletContext, UIComponent parent) throws IOException {
if (!ComponentHandler.isNew(parent)) {
return;
}
String eventName = getEventName();
if (UIComponent.isCompositeComponent(parent)) {
boolean tagApplied = false;
if (parent instanceof ClientBehaviorHolder) {
applyAttachedObject(faceletContext, parent);
tagApplied = true;
}
BeanInfo componentBeanInfo = (BeanInfo) parent.getAttributes().get(UIComponent.BEANINFO_KEY);
if (null == componentBeanInfo) {
throw new TagException(tag, "Composite component does not have BeanInfo attribute");
}
BeanDescriptor componentDescriptor = componentBeanInfo.getBeanDescriptor();
if (null == componentDescriptor) {
throw new TagException(tag, "Composite component BeanInfo does not have BeanDescriptor");
}
List<AttachedObjectTarget> targetList = (List<AttachedObjectTarget>) componentDescriptor.getValue(AttachedObjectTarget.ATTACHED_OBJECT_TARGETS_KEY);
if (null == targetList && !tagApplied) {
throw new TagException(tag, "Composite component does not support behavior events");
}
boolean supportedEvent = false;
if (targetList != null) {
for (int i = 0; i < targetList.size(); i++) {
AttachedObjectTarget target = targetList.get(i);
if (target instanceof BehaviorHolderAttachedObjectTarget) {
BehaviorHolderAttachedObjectTarget behaviorTarget = (BehaviorHolderAttachedObjectTarget) target;
if ((null != eventName && eventName.equals(behaviorTarget.getName())) || (null == eventName && behaviorTarget.isDefaultEvent())) {
supportedEvent = true;
break;
}
}
}
}
if (supportedEvent) {
// Workaround to implementation specific composite component handlers
FacesContext context = FacesContext.getCurrentInstance();
PrimeEnvironment environment = PrimeApplicationContext.getCurrentInstance(context).getEnvironment();
if (environment.isMojarra()) {
addAttachedObjectHandlerToMojarra(environment, parent);
} else {
addAttachedObjectHandlerToMyFaces(parent, faceletContext);
}
} else {
if (!tagApplied) {
throw new TagException(tag, "Composite component does not support event " + eventName);
}
}
} else if (parent instanceof ClientBehaviorHolder) {
applyAttachedObject(faceletContext, parent);
} else {
throw new TagException(tag, "Unable to attach behavior to non-ClientBehaviorHolder parent");
}
}
Aggregations