Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.dev.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.List;
 

BehaviorBase is a convenience base class that provides a default implementation of the Behavior contract. It also provides behavior listener registration and state saving support.

Since:
2.0
 
 public class BehaviorBase implements BehaviorPartialStateHolder {

 

Our javax.faces.event.BehaviorListeners. This data structure is lazily instantiated as necessary.

 
     private List<BehaviorListenerlisteners;
 
     // Flag indicating a desire to not participate in state saving.
     private boolean transientFlag = false;
 
     // Flag indicating that initial state has been marked.
     private boolean initialState = false;

    

Default implementation of Behavior.broadcast(javax.faces.event.BehaviorEvent). Delivers the specified javax.faces.event.BehaviorEvent to all registered javax.faces.event.BehaviorListener event listeners who have expressed an interest in events of this type. Listeners are called in the order in which they were registered (added).

Parameters:
event The javax.faces.event.BehaviorEvent to be broadcast
Throws:
javax.faces.event.AbortProcessingException Signal the JavaServer Faces implementation that no further processing on the current event should be performed
java.lang.IllegalArgumentException if the implementation class of this javax.faces.event.BehaviorEvent is not supported by this component
java.lang.NullPointerException if event is null
Since:
2.0
 
     public void broadcast(BehaviorEvent event)
         throws AbortProcessingException {
 
         if (null == event) {
            throw new NullPointerException();
        }
        if (null != ) {
            for (BehaviorListener listener : ) {
                if (event.isAppropriateListener(listener)) {
                    event.processListener(listener);
                }
            }
        }
    }

    
    public boolean isTransient() {
        return ;
    }

    
    public void setTransient(boolean transientFlag) {
        this. = transientFlag;
    }

    
    public Object saveState(FacesContext context) {
        if (context == null) {
            throw new NullPointerException();
        }
        
        // If initial state has been marked, we don't need to
        // save any state.
        if (initialStateMarked()) {
            return null;
        }
        // At the moment, the only state we need to save is our listeners
        return UIComponentBase.saveAttachedState(context);
    }

    
    @SuppressWarnings("unchecked")
    public void restoreState(FacesContext contextObject state) {
        if (context == null) {
            throw new NullPointerException();
        }
        if (state != null) {
            // Unchecked cast from Object to List<BehaviorListener>
             = (List<BehaviorListener>)UIComponentBase.restoreAttachedState(contextstate);
            // If we saved state last time, save state again next time.
            clearInitialState();
        }
    }

  
    
    public void markInitialState() {
         = true;
    }

    
    public boolean initialStateMarked() {
        return ;
    }

    

Clears the initial state flag, causing the behavior to revert from partial to full state saving.

    public void clearInitialState() {
         = false;
    }

    

Add the specified javax.faces.event.BehaviorListener to the set of listeners registered to receive event notifications from this Behavior. It is expected that Behavior classes acting as event sources will have corresponding typesafe APIs for registering listeners of the required type, and the implementation of those registration methods will delegate to this method. For example:

 public class AjaxBehaviorEvent extends BehaviorEvent { ... }

 public interface AjaxBehaviorListener extends BehaviorListener {
   public void processAjaxBehavior(FooEvent event);
 }

 public class AjaxBehavior extends ClientBehaviorBase {
   ...
   public void addAjaxBehaviorListener(AjaxBehaviorListener listener) {
     addBehaviorListener(listener);
   }
   public void removeAjaxBehaviorListener(AjaxBehaviorListener listener) {
     removeBehaviorListener(listener);
   }
   ...
 }
 

Parameters:
listener The javax.faces.event.BehaviorListener to be registered
Throws:
java.lang.NullPointerException if listener is null
Since:
2.0
    protected void addBehaviorListener(BehaviorListener listener) {
        if (listener == null) {
            throw new NullPointerException();
        }
        if ( == null) {
            //noinspection CollectionWithoutInitialCapacity
             = new ArrayList<BehaviorListener>();
        }
        .add(listener);
        clearInitialState();
    }

    

Remove the specified javax.faces.event.BehaviorListener from the set of listeners registered to receive event notifications from this Behavior.

Parameters:
listener The javax.faces.event.BehaviorListener to be deregistered
Throws:
java.lang.NullPointerException if listener is null
Since:
2.0
    protected void removeBehaviorListener(BehaviorListener listener) {
        if (listener == null) {
            throw new NullPointerException();
        }
        if ( == null) {
            return;
        }
        .remove(listener);
        clearInitialState();
    }
New to GrepCode? Check out our FAQ X