org.richfaces.component.AbstractAttachQueue Maven / Gradle / Ivy
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.richfaces.component;
import java.util.ArrayList;
import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ComponentSystemEvent;
import javax.faces.event.ComponentSystemEventListener;
import javax.faces.event.ListenerFor;
import javax.faces.event.PostAddToViewEvent;
import org.ajax4jsf.component.behavior.AjaxBehavior;
import org.ajax4jsf.renderkit.AjaxRendererUtils;
import org.richfaces.cdk.annotations.Attribute;
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.cdk.annotations.Tag;
import org.richfaces.cdk.annotations.TagType;
/**
* @author Nick Belaevski
*
*/
@JsfComponent(renderer=@JsfRenderer(type="org.richfaces.AttachQueueRenderer"),
tag = @Tag(name = "attachQueue",
handler = "org.richfaces.view.facelets.html.AttachQueueHandler",
generate = false, type = TagType.Facelets)
)
@ListenerFor(systemEventClass = PostAddToViewEvent.class)
public abstract class AbstractAttachQueue extends UIComponentBase implements ComponentSystemEventListener {
public static final String COMPONENT_TYPE = "org.richfaces.AttachQueue";
public static final String COMPONENT_FAMILY = "org.richfaces.AttachQueue";
private transient List componentsToAssociate;
private transient List behaviorsToAssociate;
@Attribute
public abstract String getRequestGroupingId();
@Attribute
public abstract int getRequestDelay();
@Attribute
public abstract int getTimeout();
@Attribute
public abstract boolean isIgnoreDupResponses();
@Attribute
public abstract String getOnrequestqueue();
@Attribute
public abstract String getOnrequestdequeue();
@Attribute
public abstract String getName();
public String getQueueId() {
return getName();
}
@Override
public String getFamily() {
return COMPONENT_FAMILY;
}
private static void immediateAssociateWith(UIComponent component, String queueId) {
component.getAttributes().put(AjaxRendererUtils.QUEUE_ID_ATTRIBUTE, queueId);
}
private static void immediateAssociateWith(AjaxBehavior behavior, String queueId) {
behavior.setQueueId(queueId);
}
/**
* Establishes association between attachQueue component and component passed as method argument.
* Association can be established either immediately just before returning from this method, or postponed
* until attachQueue component will be added to view.
*
* @param component
*/
public void associateWith(UIComponent component) {
if (isInView()) {
immediateAssociateWith(component, getClientId());
} else {
if (componentsToAssociate == null) {
componentsToAssociate = new ArrayList(2);
}
componentsToAssociate.add(component);
}
}
/**
* Establishes association between attachQueue component and behavior passed as method argument.
* Association can be established either immediately just before returning from this method, or postponed
* until attachQueue component will be added to view.
*
* @param behavior
*/
public void associateWith(AjaxBehavior behavior) {
if (isInView()) {
immediateAssociateWith(behavior, getClientId());
} else {
if (behaviorsToAssociate == null) {
behaviorsToAssociate = new ArrayList(2);
}
behaviorsToAssociate.add(behavior);
}
}
@Override
public void processEvent(ComponentSystemEvent event) throws AbortProcessingException {
super.processEvent(event);
if (event instanceof PostAddToViewEvent) {
String queueId = getClientId();
if (componentsToAssociate != null) {
for (UIComponent componentToAssociate : componentsToAssociate) {
immediateAssociateWith(componentToAssociate, queueId);
}
componentsToAssociate = null;
}
if (behaviorsToAssociate != null) {
for (AjaxBehavior ajaxBehavior : behaviorsToAssociate) {
immediateAssociateWith(ajaxBehavior, queueId);
}
behaviorsToAssociate = null;
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy