Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2009, 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.view.facelets.html;
 
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import  javax.faces.application.Application;
 import  javax.faces.component.StateHolder;
 import  javax.faces.component.behavior.ClientBehavior;
 import  javax.faces.component.behavior.ClientBehaviorHint;
 import  javax.faces.component.behavior.ClientBehaviorHolder;
 import  javax.faces.context.FacesContext;

Author(s):
Nick Belaevski This class is necessary to handle nesting wrapping behaviors properly and is created to work around this issue: https://javaserverfaces-spec-public.dev.java.net/issues/show_bug.cgi?id=655
 
 
 // TODO - check for bug resolution
 final class BehaviorStack {
     private static final String BEHAVIOR_STACK = "org.richfaces.BehaviorStack";
     private LinkedList<BehaviorInfoImplbehaviorStack = null;
 
     public BehaviorStack() {
          = new LinkedList<BehaviorInfoImpl>();
     }
 
     public static BehaviorStack getBehaviorStack(FacesContext contextboolean createIfNull) {
         Map<ObjectObjectattributes = context.getAttributes();
         BehaviorStack behaviorStack = (BehaviorStackattributes.get();
 
         if (behaviorStack == null && createIfNull) {
             behaviorStack = new BehaviorStack();
             attributes.put(behaviorStack);
         }
 
         return behaviorStack;
     }
 
     public boolean isEmpty() {
         return .isEmpty();
     }
 
     public void addBehaviors(FacesContext context, ClientBehaviorHolder behaviorHolder) {
         if ( == null || .isEmpty()) {
             return;
         }
 
         for (BehaviorInfoImpl behaviorInfo : ) {
             behaviorInfo.addBehavior(contextbehaviorHolder);
         }
     }
 
     public void pushBehavior(FacesContext context, ClientBehavior clientBehaviorString behaviorIdString eventName) {
 
         Object behaviorState = ((StateHolder) clientBehavior).saveState(context);
 
         // closer behaviors are processed earlier
         .addFirst(new BehaviorInfoImpl(behaviorIdeventNamebehaviorState));
     }
 
     public BehaviorInfo popBehavior() {
         if (!.isEmpty()) {
             return .removeFirst();
         } else {
             return null;
         }
     }
 
     static interface BehaviorInfo {
         List<ClientBehavior> getBehaviors();
     }
 
    private static class BehaviorInfoImpl implements BehaviorInfo {
        private String behaviorId;
        private Object behaviorState;
        private String eventName;
        private List<ClientBehavior> behaviors;
        public BehaviorInfoImpl(String behaviorIdString eventNameObject behaviorState) {
            this. = behaviorId;
            this. = eventName;
            this. = behaviorState;
        }
        private void addBehavior(FacesContext context, ClientBehaviorHolder behaviorHolder) {
            String eventName = this.;
            if (eventName == null) {
                eventName = behaviorHolder.getDefaultEventName();
                if (eventName == null) {
                    return;
                }
            }
            if (shouldAddBehavior(behaviorHoldereventName)) {
                ClientBehavior behavior = createBehavior(context);
                behaviorHolder.addClientBehavior(eventNamebehavior);
            }
        }
        public List<ClientBehavior> getBehaviors() {
            return ;
        }
        private boolean shouldAddBehavior(ClientBehaviorHolder behaviorHolderString eventName) {
            if (!behaviorHolder.getEventNames().contains(eventName)) {
                return false;
            }
            Map<StringList<ClientBehavior>> clientBehaviorsMap = behaviorHolder.getClientBehaviors();
            List<ClientBehavior> clientBehaviors = clientBehaviorsMap.get(eventName);
            if (clientBehaviors == null || clientBehaviors.isEmpty()) {
                return true;
            }
            for (ClientBehavior behavior : clientBehaviors) {
                Set<ClientBehaviorHint> hints = behavior.getHints();
                if (hints.contains(ClientBehaviorHint.SUBMITTING)) {
                    return false;
                }
            }
            return true;
        }
        private ClientBehavior createBehavior(FacesContext context) {
            Application application = context.getApplication();
            ClientBehavior behavior = (ClientBehavior) application.createBehavior(this.);
            ((StateHolder) behavior).restoreState(context);
            if ( == null) {
                 = new ArrayList<ClientBehavior>();
            }
            .add(behavior);
            return behavior;
        }
    }
New to GrepCode? Check out our FAQ X