All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.butterfaces.resolver.ClientBehaviorResolver Maven / Gradle / Ivy

There is a newer version: 3.5.0
Show newest version
package org.butterfaces.resolver;

import javax.faces.component.UIComponentBase;
import javax.faces.component.behavior.AjaxBehavior;
import javax.faces.component.behavior.ClientBehavior;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public class ClientBehaviorResolver {

    public static Optional findFirstActiveAjaxBehavior(final UIComponentBase component, final String eventName) {
        if (component != null) {
            final List behaviors = component.getClientBehaviors().get(eventName);
            if (behaviors != null) {
                for (ClientBehavior behavior : behaviors) {
                    if (behavior instanceof AjaxBehavior && !((AjaxBehavior) behavior).isDisabled()) {
                        return Optional.of((AjaxBehavior) behavior);
                    }
                }
            }
        }

        return Optional.empty();
    }

    /**
     * @deprecated use {@link ClientBehaviorResolver#findFirstActiveAjaxBehavior(UIComponentBase, String)} instead
     */
    @Deprecated
    public static AjaxBehavior resolveActiveAjaxBehavior(final UIComponentBase component, final String event) {
        return findAjaxBehavior(component.getClientBehaviors(), event);
    }

    private static AjaxBehavior findAjaxBehavior(Map> behaviors, String event) {
        if (behaviors.containsKey(event)) {
            final ClientBehavior clientBehavior = behaviors.get(event).get(0);

            if (clientBehavior instanceof AjaxBehavior && !((AjaxBehavior) clientBehavior).isDisabled()) {
                return ((AjaxBehavior) clientBehavior);
            }
        }

        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy