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

javax.faces.component.behavior.ClientBehaviorContext Maven / Gradle / Ivy

Go to download

This is the master POM file for Oracle's Implementation of the JSF 2.3 Specification.

There is a newer version: 2.3-pfd
Show newest version
/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
 *
 * The contents of this file are subject to the terms of either the GNU
 * General Public License Version 2 only ("GPL") or the Common Development
 * and Distribution License("CDDL") (collectively, the "License").  You
 * may not use this file except in compliance with the License.  You can
 * obtain a copy of the License at
 * https://glassfish.java.net/public/CDDL+GPL_1_1.html
 * or packager/legal/LICENSE.txt.  See the License for the specific
 * language governing permissions and limitations under the License.
 *
 * When distributing the software, include this License Header Notice in each
 * file and include the License file at packager/legal/LICENSE.txt.
 *
 * GPL Classpath Exception:
 * Oracle designates this particular file as subject to the "Classpath"
 * exception as provided by Oracle in the GPL Version 2 section of the License
 * file that accompanied this code.
 *
 * Modifications:
 * If applicable, add the following below the License Header, with the fields
 * enclosed by brackets [] replaced by your own identifying information:
 * "Portions Copyright [year] [name of copyright owner]"
 *
 * Contributor(s):
 * If you wish your version of this file to be governed by only the CDDL or
 * only the GPL Version 2, indicate your decision by adding "[Contributor]
 * elects to include this software in this distribution under the [CDDL or GPL
 * Version 2] license."  If you don't indicate a single choice of license, a
 * recipient has the option to distribute your version of this file under
 * either the CDDL, the GPL Version 2 or to extend the choice of license to
 * its licensees as provided above.  However, if you add GPL Version 2 code
 * and therefore, elected the GPL Version 2 license, then the option applies
 * only if the new code is made subject to such option by the copyright
 * holder.
 */

package javax.faces.component.behavior;

import java.util.Collection;
import java.util.Collections;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

/**
 * 

ClientBehaviorContext * provides context information that may be useful to * {@link javax.faces.component.behavior.ClientBehavior#getScript} * implementations. *

* * @since 2.0 */ public abstract class ClientBehaviorContext { /** *

Creates a ClientBehaviorContext instance.

* * @param context the FacesContext for the current request. * @param component the component instance to which the * ClientBehavior is attached. * @param eventName the name of the behavior event to which the * ClientBehavior is attached. * @param sourceId the id to use as the ClientBehavior's "source". * @param parameters the collection of parameters for submitting * ClientBehaviors to include in the request. * @return a ClientBehaviorContext instance configured with the * provided values. * @throws NullPointerException if context, * component or eventName * is null * * @since 2.0 */ public static ClientBehaviorContext createClientBehaviorContext(FacesContext context, UIComponent component, String eventName, String sourceId, Collection parameters) { return new ClientBehaviorContextImpl(context, component, eventName, sourceId, parameters); } /** *

Returns the {@link FacesContext} for * the current request.

* * @return the {@link FacesContext}. * * @since 2.0 */ abstract public FacesContext getFacesContext(); /** *

Returns the {@link UIComponent} that is * requesting the {@link ClientBehavior} script.

* * @return the component. * * @since 2.0 */ abstract public UIComponent getComponent(); /** *

Returns the name of the behavior event * for which the ClientBehavior script is being requested.

* * @return the event name. * * @since 2.0 */ abstract public String getEventName(); /** *

Returns an id for use as the * {@link ClientBehavior} source. ClientBehavior implementations that submit back * to the Faces lifecycle are required to identify which component * triggered the ClientBehavior-initiated request via the * javax.faces.source request parameter. In * most cases, th source id can be trivially derived from the element * to which the behavior's client-side script is attached - ie. the * source id is typically the id of this element. However, in components * which produce more complex content, the behavior script may not be able to * determine the correct id to use for the javax.faces.source * value. The {@link ClientBehaviorContext#getSourceId} method allows the component * to pass this information into the {@link ClientBehavior#getScript} * implementation.

* * @return the id for the behavior's script to use as the "source", or * null if the Behavior's script can identify the source from the DOM. * * @since 2.0 */ abstract public String getSourceId(); /** *

Returns parameters that "submitting" * {@link ClientBehavior} implementations should include when posting back data * into the Faces lifecycle. If no parameters are specified, this method * returns an empty (non-null) collection.

* * @return the parameters. * * @since 2.0 */ abstract public Collection getParameters(); // Little static member class that provides a default implementation private static final class ClientBehaviorContextImpl extends ClientBehaviorContext { private FacesContext context; private UIComponent component; private String eventName; private String sourceId; private Collection parameters; private ClientBehaviorContextImpl(FacesContext context, UIComponent component, String eventName, String sourceId, Collection parameters) { if (null == context) { throw new NullPointerException(); } if (null == component) { throw new NullPointerException(); } if (null == eventName) { throw new NullPointerException(); } this.context = context; this.component = component; this.eventName = eventName; this.sourceId = sourceId; this.parameters = (parameters == null) ? Collections.emptyList() : parameters; } @Override public FacesContext getFacesContext() { return context; } @Override public UIComponent getComponent() { return component; } @Override public String getEventName() { return eventName; } @Override public String getSourceId() { return sourceId; } @Override public Collection getParameters() { return parameters; } } /** *

Parameter instances * represent name/value pairs that "submitting" ClientBehavior implementations * should include when posting back into the Faces lifecycle. ClientBehavior * implementations can determine which Parameters to include by calling * ClientBehaviorContext.getParameters(). *

* * @since 2.0 */ public static class Parameter { private String name; private Object value; /** *

Creates a Parameter instance.

* @param name the name of the parameter * @param value the value of the parameter * @throws NullPointerException if name * is null. * * @since 2.0 */ public Parameter(String name, Object value) { if (null == name) { throw new NullPointerException(); } this.name = name; this.value = value; } /** *

Returns the Parameter's name.

* * @return the parameter's name. * * @since 2.0 */ public String getName() { return name; } /** *

Returns the Parameter's value.

* * @return the parameter's value. * * @since 2.0 */ public Object getValue() { return value; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy