Application application = ctx.getFacesContext().getApplication();
Behavior behavior = application.createBehavior(getBehaviorId());
if (behavior instanceof AjaxBehavior) {
setAttributes(ctx, behavior);
AjaxBehavior ajaxBehavior = (AjaxBehavior) behavior;
FacesContext context = ctx.getFacesContext();
BehaviorStack ajaxBehaviors = BehaviorStack.getBehaviorStack(context, true);
String eventName = getEventName();
ajaxBehaviors.pushBehavior(context, ajaxBehavior, getBehaviorId(), eventName);
AttachQueueStack attachQueueStack = AttachQueueStack.getStack(context, true);
AttachQueueInfo attachQueueInfo = new AttachQueueInfo(parent);
attachQueueStack.push(attachQueueInfo);
nextHandler.apply(ctx, parent);
attachQueueStack.pop();
BehaviorInfo behaviorInfo = ajaxBehaviors.popBehavior();
if (behaviorInfo != null) {
if (isWrapping()) {
AbstractAttachQueue attachQueue = attachQueueInfo.getAttachQueue();
if (attachQueue != null) {
List<ClientBehavior> behaviors = behaviorInfo.getBehaviors();
if (behaviors != null) {
for (ClientBehavior processBehavior : behaviors) {
if (processBehavior instanceof AjaxBehavior) {
AjaxBehavior createdAjaxBehavior = (AjaxBehavior) processBehavior;
attachQueue.associateWith(createdAjaxBehavior);
}
}
}
}