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;
  
  
  
  import java.util.HashMap;
  import java.util.List;
  import java.util.Locale;
  import java.util.Map;

UIViewRoot is the UIComponent that represents the root of the UIComponent tree. This component renders markup as the response to Ajax requests. It also serves as the root of the component tree, and as a place to hang per-view javax.faces.event.PhaseListeners.

For each of the following lifecycle phase methods:

Take the following action regarding PhaseListeners.

 
 
 public class UIViewRoot extends UIComponentBase implements UniqueIdVendor {
 
     // ------------------------------------------------------ Manifest Constants
 
     public static final String METADATA_FACET_NAME = "javax_faces_metadata";
    
    

The key in the value set of the view metadata BeanDescriptor, the value of which is a List<UIViewParameter.Reference>.

Since:
2.0
 
     public static final String VIEW_PARAMETERS_KEY = "javax.faces.component.VIEW_PARAMETERS_KEY";
    
    

The standard component type for this component.

 
     public static final String COMPONENT_TYPE = "javax.faces.ViewRoot";


    

The standard component family for this component.

 
     public static final String COMPONENT_FAMILY = "javax.faces.ViewRoot";


    

The prefix that will be used for identifiers generated by the createUniqueId() method.

 
     static public final String UNIQUE_ID_PREFIX = "j_id";
 
     private static Lifecycle lifecycle;
 
     private static final Logger LOGGER =
           Logger.getLogger("javax.faces""javax.faces.LogStrings");
 
     private static final String LOCATION_IDENTIFIER_PREFIX = "javax_faces_location_";
     private static final Map<String,StringLOCATION_IDENTIFIER_MAP =
           new HashMap<String,String>(6, 1.0f);
     static {
         .put("head" + "HEAD");
         .put("form" + "FORM");
         .put("body" + "BODY");        
     }
 
     enum PropertyKeys {
        

The render kit identifier of the javax.faces.render.RenderKit associated wth this view.

 
         renderKitId,
        

The view identifier of this view.

 
         viewId,
         locale,
         lastId,
         beforePhase,
         afterPhase,
         phaseListeners,
         viewScope  // RELEASE_PENDING
     }
 
 
     // ------------------------------------------------------------ Constructors
 

    

Create a new UIViewRoot instance with default property values.

 
     public UIViewRoot() {
 
         super();
         setRendererType(null);
         setId(createUniqueId());
 
     }
 
     // ------------------------------------------------------ Instance Variables
 

    

Set and cleared during the lifetime of a lifecycle phase. Has no meaning between phases. If true, the lifecycle processing for the current phase must not take place.

 
     private boolean skipPhase;

    

Set and cleared during the lifetime of a lifecycle phase. Has no meaning between phases. If true, the MethodExpression associated with afterPhase will not be invoked nor will any PhaseListeners associated with this UIViewRoot.

 
     private boolean beforeMethodException;

    

Set and cleared during the lifetime of a lifecycle phase. Has no meaning between phases.

 
 
 
     // -------------------------------------------------------------- Properties
 

    

Return trues.

Since:
2.0
 
     @Override
     public boolean isInView() {
 
         return true;
 
     }

    

Overridden to take no action.

Parameters:
isInView
Since:
2.0
 
     @Override
     public void setInView(boolean isInView) {
         // no-op
     }

    
 
     public String getFamily() {
 
         return ();
 
     }


    

Return the render kit identifier of the javax.faces.render.RenderKit associated with this view. Unless explicitly set, as in javax.faces.application.ViewHandler.createView(javax.faces.context.FacesContext,java.lang.String), the returned value will be null.

 
     public String getRenderKitId() {
 
         return (StringgetStateHelper().eval(.);
 
     }


    

Set the render kit identifier of the javax.faces.render.RenderKit associated with this view. This method may be called at any time between the end of Apply Request Values phase of the request processing lifecycle (i.e. when events are being broadcast) and the beginning of the Render Response phase.

Parameters:
renderKitId The new javax.faces.render.RenderKit identifier, or null to disassociate this view with any specific javax.faces.render.RenderKit instance
 
     public void setRenderKitId(String renderKitId) {
 
         getStateHelper().put(.renderKitId);
 
     }


    

Return the view identifier for this view.

 
     public String getViewId() {
 
         return (StringgetStateHelper().get(.);
 
     }


    

Set the view identifier for this view.

Parameters:
viewId The new view identifier
 
     public void setViewId(String viewId) {
 
         getStateHelper().put(.viewId);
 
     }
 
     // ------------------------------------------------ Event Management Methods
 

    

Return the javax.el.MethodExpression that will be invoked before this view is rendered.

Returns:
the javax.el.MethodExpression that will be invoked before this view is rendered.
Since:
1.2
 
 
     }

    

Allow an arbitrary method to be called for the "beforePhase" event as the UIViewRoot runs through its lifecycle. This method will be called for all phases except javax.faces.event.PhaseId.RESTORE_VIEW. Unlike a true javax.faces.event.PhaseListener, this approach doesn't allow for only receiving javax.faces.event.PhaseEvents for a given phase.

The method must conform to the signature of javax.faces.event.PhaseListener.beforePhase(javax.faces.event.PhaseEvent).

Parameters:
newBeforePhase the javax.el.MethodExpression that will be invoked before this view is rendered.
Since:
1.2
 
     public void setBeforePhaseListener(MethodExpression newBeforePhase) {
         getStateHelper().put(.newBeforePhase);
     }

    

Return the javax.el.MethodExpression that will be invoked after this view is rendered.

Returns:
the javax.el.MethodExpression that will be invoked after this view is rendered.
Since:
1.2
 
     }

    

Allow an arbitrary method to be called for the "afterPhase" event as the UIViewRoot runs through its lifecycle. This method will be called for all phases including javax.faces.event.PhaseId.RESTORE_VIEW. Unlike a true javax.faces.event.PhaseListener, this approach doesn't allow for only receiving javax.faces.event.PhaseEvents for a given phase.

The method must conform to the signature of javax.faces.event.PhaseListener.afterPhase(javax.faces.event.PhaseEvent).

Parameters:
newAfterPhase the javax.el.MethodExpression that will be invoked after this view is rendered.
Since:
1.2
 
     public void setAfterPhaseListener(MethodExpression newAfterPhase) {
         getStateHelper().put(.newAfterPhase);
     }


    

If the argument toRemove is in the list of javax.faces.event.PhaseListeners for this instance, it must be removed.

Parameters:
toRemove the javax.faces.event.PhaseListener to remove.
Since:
1.2
 
     public void removePhaseListener(PhaseListener toRemove) {
 
         getStateHelper().remove(.toRemove);
     }

    

Add the argument newPhaseListener to the list of javax.faces.event.PhaseListeners on this UIViewRoot.

Parameters:
newPhaseListener the javax.faces.event.PhaseListener to add
Since:
1.2
 
     public void addPhaseListener(PhaseListener newPhaseListener) {
 
         getStateHelper().add(.newPhaseListener);
 
     }

    
    

Return an unmodifiable list of the PhaseListener instances attached to this UIViewRoot instance.

Since:
2.0
 
     public List<PhaseListenergetPhaseListeners() {
 
         //noinspection unchecked
         List<PhaseListenerresult = (List<PhaseListener>)
               getStateHelper().get(.);
 
         return ((result != null)
                 ? Collections.unmodifiableList(result)
                 : Collections.unmodifiableList(Collections.<PhaseListener>emptyList()));
 
     }

    

Add argument component, which is assumed to represent a resource instance, as a resource to this view. A resource instance is rendered by a resource Renderer, as described in the Standard HTML RenderKit. The default implementation must call through to addComponentResource(javax.faces.context.FacesContext,javax.faces.component.UIComponent,java.lang.String).

Parameters:
context javax.faces.context.FacesContext for the current request
componentResource The UIComponent representing a javax.faces.application.Resource instance
Since:
2.0
 
     public void addComponentResource(FacesContext contextUIComponent componentResource) {
         addComponentResource(contextcomponentResourcenull);
     }

    

Add argument component, which is assumed to represent a resource instance, as a resource to this view. A resource instance is rendered by a resource Renderer, as described in the Standard HTML RenderKit.

The component must be added using the following algorithm:

  • If the target argument is null, look for a target attribute on the component. If there is no target attribute, set target to be the default value head

  • Call getComponentResources(javax.faces.context.FacesContext,java.lang.String) to obtain the child list for the given target.

  • If the component ID of componentResource matches the the ID of a resource that has allready been added, remove the old resource.

  • Add the component resource to the list.

Parameters:
context javax.faces.context.FacesContext for the current request
componentResource The UIComponent representing a javax.faces.application.Resource instance
target The name of the facet for which the UIComponent will be added
Since:
2.0
 
     public void addComponentResource(FacesContext contextUIComponent componentResourceString target) {
         final Map<String,Objectattributes = componentResource.getAttributes();
         // look for a target in the component attribute set if arg is not set.
         if (target == null) {
             target = (Stringattributes.get("target");
         }
         if (target == null) {
             target = "head";
         }
         List<UIComponentfacetChildren = getComponentResources(context,
                                                                 target,
                                                                 true);
         String id = componentResource.getId();
         if (id != null) {
             for (UIComponent c : facetChildren) {
                 if (id.equals(c.getId())) {
                     facetChildren.remove(c);
                 }
             }
         }
         // add the resource to the facet
         facetChildren.add(componentResource);
     }

    

Return an unmodifiable List of UIComponents for the provided target agrument. Each component in the List is assumed to represent a resource instance.

The default implementation must use an algorithm equivalent to the the following.

  • Locate the facet for the component by calling getFacet() using target as the argument.
  • If the facet is not found, create the facet by calling context.getApplication().createComponent(). The argument to this method must refer to a component that extends UIPanel and overrides the encodeAll() method to take no action. This is necessary to prevent component resources from being inadvertently rendered.
    • Set the id of the facet to be a string created by prepending the literal string “javax_faces_location_” (without the quotes) to the value of the target argument
    • Add the facet to the facets Map using target as the key
  • return the children of the facet

Parameters:
target The name of the facet for which the components will be returned.
Returns:
A List of UIComponent children of the facet with the name target. If no children are found for the facet, return Collections.emptyList().
Throws:
java.lang.NullPointerException if target or context is null
Since:
2.0
 
     public List<UIComponentgetComponentResources(FacesContext context
                                                    String target) {
         if (target == null) {
             throw new NullPointerException();
         }
 
         List<UIComponentresources = getComponentResources(context,
                                                             target,
                                                             false);
 
         return ((resources != null)
                 ? resources
                 : Collections.<UIComponent>emptyList());
 
     }
    
    

Remove argument component, which is assumed to represent a resource instance, as a resource to this view.

Parameters:
context javax.faces.context.FacesContext for the current request
componentResource The UIComponent representing a javax.faces.application.Resource instance
Since:
2.0
 
     public void removeComponentResource(FacesContext contextUIComponent componentResource) {
         removeComponentResource(contextcomponentResourcenull);
     }
    
    

Remove argument component, which is assumed to represent a resource instance, as a resource to this view. A resource instance is rendered by a resource Renderer, as described in the Standard HTML RenderKit.

The component must be removed using the following algorithm:

Parameters:
context javax.faces.context.FacesContext for the current request
componentResource The UIComponent representing a javax.faces.application.Resource instance
target The name of the facet for which the UIComponent will be added
Since:
2.0
 
     public void removeComponentResource(FacesContext contextUIComponent componentResourceString target) {
 
         final Map<String,Objectattributes = componentResource.getAttributes();
         // look for a target in the component attribute set if arg is not set.
         if (target == null) {
             target = (Stringattributes.get("target");
         }
         if (target == null) {
             target = "head";
         }
         List<UIComponentfacetChildren = getComponentResources(context,
                                                                 target,
                                                                 false);
         if (facetChildren != null) {
             facetChildren.remove(componentResource);
         }
 
     }

    

An array of Lists of events that have been queued for later broadcast, with one List for each lifecycle phase. The list indices match the ordinals of the PhaseId instances. This instance is lazily instantiated. This list is NOT part of the state that is saved and restored for this component.

 
     private List<List<FacesEvent>> events = null;


    

Override the default UIComponentBase.queueEvent(javax.faces.event.FacesEvent) behavior to accumulate the queued events for later broadcasting.

Parameters:
event javax.faces.event.FacesEvent to be queued
Throws:
java.lang.IllegalStateException if this component is not a descendant of a UIViewRoot
java.lang.NullPointerException if event is null
 
     public void queueEvent(FacesEvent event) {
 
         if (event == null) {
             throw new NullPointerException();
         }
         // We are a UIViewRoot, so no need to check for the ISE
         if ( == null) {
             int len = ..size();
             List<List<FacesEvent>> events = new ArrayList<List<FacesEvent>>(len);
             for (int i = 0; i < leni++) {
                 events.add(new ArrayList<FacesEvent>(5));
             }
             this. = events;
         }
         .get(event.getPhaseId().getOrdinal()).add(event);
     }


    

Broadcast any events that have been queued. First broadcast events that have been queued for javax.faces.event.PhaseId.ANY_PHASE. Then broadcast ane events that have been queued for the current phase. In both cases, UIComponent.pushComponentToEL(javax.faces.context.FacesContext,javax.faces.component.UIComponent) must be called before the event is broadcast, and UIComponent.popComponentFromEL(javax.faces.context.FacesContext) must be called after the return from the broadcast, even in the case of an exception.

Parameters:
context javax.faces.context.FacesContext for the current request
phaseId javax.faces.event.PhaseId of the current phase
Since:
2.0
 
     public void broadcastEvents(FacesContext contextPhaseId phaseId) {
 
         if (null == ) {
             // no events have been queued
             return;
         }
         boolean hasMoreAnyPhaseEvents;
         boolean hasMoreCurrentPhaseEvents;
 
         List<FacesEventeventsForPhaseId =
              .get(..getOrdinal());
 
         // keep iterating till we have no more events to broadcast.
         // This is necessary for events that cause other events to be
         // queued.  PENDING(edburns): here's where we'd put in a check
         // to prevent infinite event queueing.
         do {
             // broadcast the ANY_PHASE events first
             if (null != eventsForPhaseId) {
                 // We cannot use an Iterator because we will get
                 // ConcurrentModificationException errors, so fake it
                 while (!eventsForPhaseId.isEmpty()) {
                     FacesEvent event =
                           eventsForPhaseId.get(0);
                     UIComponent source = event.getComponent();
                     UIComponent compositeParent = null;
                     try {
                         if (!UIComponent.isCompositeComponent(source)) {
                             compositeParent = UIComponent.getCompositeComponentParent(source);
                         }
                         if (compositeParent != null) {
                             compositeParent.pushComponentToEL(contextnull);
                         }
                         source.pushComponentToEL(contextnull);
                         source.broadcast(event);
                     } catch (AbortProcessingException e) {
                         context.getApplication().publishEvent(context,
                                                               ExceptionQueuedEvent.class,
                                                               new ExceptionQueuedEventContext(context,
                                                                                         e,
                                                                                         source,
                                                                                         phaseId));
                     }
                     finally {
                         source.popComponentFromEL(context);
                         if (compositeParent != null) {
                             compositeParent.popComponentFromEL(context);
                         }
                     }
                     eventsForPhaseId.remove(0); // Stay at current position
                 }
             }
 
             // then broadcast the events for this phase.
             if (null != (eventsForPhaseId = .get(phaseId.getOrdinal()))) {
                 // We cannot use an Iterator because we will get
                 // ConcurrentModificationException errors, so fake it
                 while (!eventsForPhaseId.isEmpty()) {
                     FacesEvent event = eventsForPhaseId.get(0);
                     UIComponent source = event.getComponent();
                     UIComponent compositeParent = null;
                     try {
                         if (!UIComponent.isCompositeComponent(source)) {
                             compositeParent = getCompositeComponentParent(source);
                         }
                         if (compositeParent != null) {
                             compositeParent.pushComponentToEL(contextnull);
                         }
                         source.pushComponentToEL(contextnull);
                         source.broadcast(event);
                     } catch (AbortProcessingException ape) {
                         // A "return" here would abort remaining events too
                         context.getApplication().publishEvent(context,
                                                               ExceptionQueuedEvent.class,
                                                               new ExceptionQueuedEventContext(context,
                                                                                         ape,
                                                                                         source,
                                                                                         phaseId));
                     }
                     finally {
                         source.popComponentFromEL(context);
                         if (compositeParent != null) {
                             compositeParent.popComponentFromEL(context);
                         }
                     }
                     eventsForPhaseId.remove(0); // Stay at current position
                 }
             }
 
             // true if we have any more ANY_PHASE events
             hasMoreAnyPhaseEvents =
                   (null != (eventsForPhaseId =
                         .get(..getOrdinal()))) &&
                         !eventsForPhaseId.isEmpty();
             // true if we have any more events for the argument phaseId
             hasMoreCurrentPhaseEvents =
                   (null != .get(phaseId.getOrdinal())) &&
                   !.get(phaseId.getOrdinal()).isEmpty();
 
         } while (hasMoreAnyPhaseEvents || hasMoreCurrentPhaseEvents);
     
     }
 
     // ------------------------------------------------ Lifecycle Phase Handlers
 
 
     private void initState() {
          = false;
          = false;
         //noinspection unchecked
         List<PhaseListenerlisteners =
               (List<PhaseListener>) getStateHelper().get(.);
          =
               ((listeners != null) ? listeners.listIterator() : null);
     }
 
     // avoid creating the PhaseEvent if possible by doing redundant
     // null checks.
     private void notifyBefore(FacesContext contextPhaseId phaseId) {
         if (getBeforePhaseListener() != null ||  != null) {
             notifyPhaseListeners(contextphaseIdtrue);
         }
     }
     
     // avoid creating the PhaseEvent if possible by doing redundant
     // null checks.
     private void notifyAfter(FacesContext contextPhaseId phaseId) {
         if (getAfterPhaseListener() != null ||  != null) {
             notifyPhaseListeners(contextphaseIdfalse);
         }
     }


    

The default implementation must call UIComponentBase.processRestoreState(javax.faces.context.FacesContext,java.lang.Object) from within a try block. The try block must have a finally block that ensures that no javax.faces.event.FacesEvents remain in the event queue.    

Parameters:
context the FacesContext for this requets
state the opaque state object obtained from the javax.faces.application.StateManager
 
     @Override
     public void processRestoreState(FacesContext contextObject state) {
 
         // hack to work around older state managers that may not set the
         // view root early enough
         if (context.getViewRoot() == null) {
             context.setViewRoot(this);
         }
         super.processRestoreState(contextstate);
 
     }
    

    

Perform partial processing by calling javax.faces.context.PartialViewContext.processPartial(javax.faces.event.PhaseId) with javax.faces.event.PhaseId.APPLY_REQUEST_VALUES if:

Perform full processing by calling UIComponentBase.processDecodes(javax.faces.context.FacesContext) if one of the following conditions are met:

Override the default UIComponentBase.processDecodes(javax.faces.context.FacesContext) behavior to broadcast any queued events after the default processing or partial processing has been completed and to clear out any events for later phases if the event processing for this phase caused javax.faces.context.FacesContext.renderResponse() or javax.faces.context.FacesContext.responseComplete() to be called.

Parameters:
context javax.faces.context.FacesContext for the request we are processing
Throws:
java.lang.NullPointerException if context is null
 
     @Override
     public void processDecodes(FacesContext context) {
         initState();
         notifyBefore(context.);
 
         try {
             if (!) {
                 if (context.getPartialViewContext().isPartialRequest() &&
                     !context.getPartialViewContext().isExecuteAll()) {
                     context.getPartialViewContext().processPartial(.);
                 } else {
                     super.processDecodes(context);
                 }
                 broadcastEvents(context.);
             }
         } finally {
             clearFacesEvents(context);
             notifyAfter(context.);
         }
     }

    

Override the default UIComponentBase.encodeBegin(javax.faces.context.FacesContext) behavior. If getBeforePhaseListener() returns non-null, invoke it, passing a javax.faces.event.PhaseEvent for the javax.faces.event.PhaseId.RENDER_RESPONSE phase. If the internal list populated by calls to addPhaseListener(javax.faces.event.PhaseListener) is non-empty, any listeners in that list must have their javax.faces.event.PhaseListener.beforePhase(javax.faces.event.PhaseEvent) method called, passing the PhaseEvent. Any errors that occur during invocation of any of the the beforePhase listeners must be logged and swallowed. After listeners are invoked call superclass processing.

 
     @Override
     public void encodeBegin(FacesContext contextthrows IOException {
         initState();
         notifyBefore(context.);
 
         if (!context.getResponseComplete()) {
             super.encodeBegin(context);
         }
     }

    
 
     @Override
     public void encodeChildren(FacesContext contextthrows IOException {
         if (context.getPartialViewContext().isAjaxRequest()) {
             context.getPartialViewContext().processPartial(.);
         } else {
             super.encodeChildren(context);
         }
     }

    

If getAfterPhaseListener() returns non-null, invoke it, passing a javax.faces.event.PhaseEvent for the javax.faces.event.PhaseId.RENDER_RESPONSE phase. Any errors that occur during invocation of the afterPhase listener must be logged and swallowed. If the current view has view parameters, as indicated by a non-empty and non-UnsupportedOperationException throwing return from javax.faces.view.ViewDeclarationLanguage.getViewMetadata(javax.faces.context.FacesContext,java.lang.String), call UIViewParameter.encodeAll(javax.faces.context.FacesContext) on each parameter. If calling getViewParameters() causes UnsupportedOperationException to be thrown, the exception must be silently swallowed.

    @Override
    public void encodeEnd(FacesContext contextthrows IOException {
        super.encodeEnd(context);
        encodeViewParameters(context);
        notifyAfter(context.);               
    }

    

Call UIComponentBase.getRendersChildren() If javax.faces.context.PartialViewContext.isAjaxRequest() returns true this method must return true.

Since:
2.0
    @Override
    public boolean getRendersChildren() {
        boolean value = super.getRendersChildren();
        FacesContext context = FacesContext.getCurrentInstance();
        if (context.getPartialViewContext().isAjaxRequest()) {
            value = true;
        }
        return value;
    }

    

Utility method that notifies phaseListeners for the given phaseId. Assumes that either or both the MethodExpression or phaseListeners data structure are non-null.

Parameters:
context the context for this request
phaseId the javax.faces.event.PhaseId of the current phase
isBefore, if true, notify beforePhase listeners. Notify afterPhase listeners otherwise.
    private void notifyPhaseListeners(FacesContext context,
                                      PhaseId phaseId,
                                      boolean isBefore) {
        PhaseEvent event = createPhaseEvent(contextphaseId);
        MethodExpression beforePhase = getBeforePhaseListener();
        MethodExpression afterPhase = getAfterPhaseListener();
        boolean hasPhaseMethodExpression =
              (isBefore && (null != beforePhase)) ||
              (!isBefore && (null != afterPhase) && !);
        MethodExpression expression = isBefore ? beforePhase : afterPhase;
        if (hasPhaseMethodExpression) {
            try {
                expression.invoke(context.getELContext(), new Object[]{event});
                 = context.getResponseComplete() ||
                            context.getRenderResponse();
            }
            catch (Exception e) {
                if (isBefore) {
                     = true;
                }
                if (.isLoggable(.)) {
                    .log(.,
                               "severe.component.unable_to_process_expression",
                               new Object[] { expression.getExpressionString(),
                                              (isBefore ? "beforePhase" : "afterPhase")});
                }
                return;
            }
        }
        if ( != null && !) {
            while ((isBefore)
                   ? .hasNext()
                   : .hasPrevious()) {
                PhaseListener curListener = ((isBefore)
                                             ? .next()
                                             : 
                                                   .previous());
                if (phaseId == curListener.getPhaseId() ||
                    . == curListener.getPhaseId()) {
                    try {
                        if (isBefore) {
                            curListener.beforePhase(event);
                        } else {
                            curListener.afterPhase(event);
                        }
                         = context.getResponseComplete() ||
                                    context.getRenderResponse();
                    }
                    catch (Exception e) {
                        if (isBefore && .hasPrevious()) {
                            .previous();
                        }
                        if (.isLoggable(.)) {
                            .log(.,
                                       "severe.component.uiviewroot_error_invoking_phaselistener",
                                       curListener.getClass().getName());
                        }
                        return;
                    }
                }
            }
        }
    }
    private static PhaseEvent createPhaseEvent(FacesContext context,
                                               PhaseId phaseId)
    throws FacesException {
        if ( == null) {
            LifecycleFactory lifecycleFactory = (LifecycleFactory)
                  FactoryFinder.getFactory(.);
            String lifecycleId =
                  context.getExternalContext()
                        .getInitParameter(.);
            if (lifecycleId == null) {
                lifecycleId = .;
            }
             = lifecycleFactory.getLifecycle(lifecycleId);
        }
        return (new PhaseEvent(contextphaseId));
    }


    

Perform partial processing by calling javax.faces.context.PartialViewContext.processPartial(javax.faces.event.PhaseId) with javax.faces.event.PhaseId.PROCESS_VALIDATIONS if:

Perform full processing by calling UIComponentBase.processValidators(javax.faces.context.FacesContext) if one of the following conditions are met:

Override the default UIComponentBase.processValidators(javax.faces.context.FacesContext) behavior to broadcast any queued events after the default processing or partial processing has been completed and to clear out any events for later phases if the event processing for this phase caused javax.faces.context.FacesContext.renderResponse() or javax.faces.context.FacesContext.responseComplete() to be called.

Parameters:
context javax.faces.context.FacesContext for the request we are processing
Throws:
java.lang.NullPointerException if context is null
    @Override
    public void processValidators(FacesContext context) {
        initState();
        notifyBefore(context.);
        try {
            if (!) {
                if (context.getPartialViewContext().isPartialRequest() &&
                    !context.getPartialViewContext().isExecuteAll()) {
                    context.getPartialViewContext().processPartial(.);
                } else {
                    super.processValidators(context);
                }
                broadcastEvents(context.);
            }
        } finally {
            clearFacesEvents(context);
            notifyAfter(context.);
        }
    }

    

Perform partial processing by calling javax.faces.context.PartialViewContext.processPartial(javax.faces.event.PhaseId) with javax.faces.event.PhaseId.UPDATE_MODEL_VALUES if:

Perform full processing by calling UIComponentBase.processUpdates(javax.faces.context.FacesContext) if one of the following conditions are met:

Override the default UIComponentBase behavior to broadcast any queued events after the default processing or partial processing has been completed and to clear out any events for later phases if the event processing for this phase caused javax.faces.context.FacesContext.renderResponse() or javax.faces.context.FacesContext.responseComplete() to be called.

Parameters:
context javax.faces.context.FacesContext for the request we are processing
Throws:
java.lang.NullPointerException if context is null
    @Override
    public void processUpdates(FacesContext context) {
        initState();
        notifyBefore(context.);
        try {
            if (!) {
                if (context.getPartialViewContext().isPartialRequest() &&
                    !context.getPartialViewContext().isExecuteAll()) {
                    context.getPartialViewContext().processPartial(.);
                } else {
                    super.processUpdates(context);
                }
                broadcastEvents(context.);
            }
        } finally {
            clearFacesEvents(context);
            notifyAfter(context.);
        }
    }

    

Broadcast any events that have been queued for the Invoke Application phase of the request processing lifecycle and to clear out any events for later phases if the event processing for this phase caused javax.faces.context.FacesContext.renderResponse() or javax.faces.context.FacesContext.responseComplete() to be called.

Parameters:
context javax.faces.context.FacesContext for the request we are processing
Throws:
java.lang.NullPointerException if context is null
    public void processApplication(FacesContext context) {
        initState();
        notifyBefore(context.);
        try {
            if (!) {
                // NOTE - no tree walk is performed; this is a UIViewRoot-only operation
                broadcastEvents(context.);
            }
        } finally {
            clearFacesEvents(context);
            notifyAfter(context.);
        }
    }
    // clear out the events if we're skipping to render-response
    // or if there is a response complete signal.
    private void clearFacesEvents(FacesContext context) {
        if (context.getRenderResponse() || context.getResponseComplete()) {
            if ( != null) {
                for (List<FacesEventeventList : ) {
                    if (eventList != null) {
                        eventList.clear();
                    }
                }
                 = null;
            }
        }
    }

    

Generate an identifier for a component. The identifier will be prefixed with UNIQUE_ID_PREFIX, and will be unique within this UIViewRoot.

    public String createUniqueId() {
        return createUniqueId(getFacesContext(), null);
    }

    

Generate an identifier for a component. The identifier will be prefixed with UNIQUE_ID_PREFIX, and will be unique within this UIViewRoot. Optionally, a unique seed value can be supplied by component creators which should be included in the generated unique id.

Parameters:
context FacesContext
seed an optional seed value - e.g. based on the position of the component in the VDL-template
Returns:
a unique-id in this component-container
    public String createUniqueId(FacesContext contextString seed) {
        if (seed != null) {
            return . + seed;
        } else {
            Integer i = (IntegergetStateHelper().get(.);
            int lastId = ((i != null) ? i : 0);
            getStateHelper().put(.,  ++lastId);
            return . + lastId;
        }
    }


    

Return the Locale to be used in localizing the response being created for this view.

Algorithm:

If we have a locale ivar, return it. If we have a value expression for "locale", get its value. If the value is null, return the result of calling javax.faces.application.ViewHandler.calculateLocale(javax.faces.context.FacesContext). If the value is an instance of java.util.Locale return it. If the value is a String, convert it to a java.util.Locale and return it. If there is no value expression for "locale", return the result of calling javax.faces.application.ViewHandler.calculateLocale(javax.faces.context.FacesContext).

Returns:
The current Locale obtained by executing the above algorithm.
    public Locale getLocale() {
        Object result = getStateHelper().eval(.);
        if (result != null) {
            Locale locale = null;
            if (result instanceof Locale) {
                    locale = (Localeresult;
            } else if (result instanceof String) {
                   locale = getLocaleFromString((Stringresult);
            }
            return locale;
        } else {
            FacesContext context = getFacesContext();
            return context.getApplication().getViewHandler().calculateLocale(context);
        }
    }
    // W3C XML specification refers to IETF RFC 1766 for language code
    // structure, therefore the value for the xml:lang attribute should
    // be in the form of language or language-country or
    // language-country-variant.
    private static Locale getLocaleFromString(String localeStr)
        throws IllegalArgumentException {
        // length must be at least 2.
        if (null == localeStr || localeStr.length() < 2) {
            throw new IllegalArgumentException("Illegal locale String: " +
                                               localeStr);
        }
        Locale result = null;
        String lang = null;
        String country = null;
        String variant = null;
        char[] seps = {
            '-',
            '_'
        };
        int inputLength = localeStr.length();
        int i = 0;
        int j = 0;
        // to have a language, the length must be >= 2
        if ((inputLength >= 2) &&
            ((i = indexOfSet(localeStrseps, 0)) == -1)) {
            // we have only Language, no country or variant
            if (2 != localeStr.length()) {
                throw new
                    IllegalArgumentException("Illegal locale String: " +
                                             localeStr);
            }
            lang = localeStr.toLowerCase();
        }
        // we have a separator, it must be either '-' or '_'
        if (i != -1) {
            lang = localeStr.substring(0, i);
            // look for the country sep.
            // to have a country, the length must be >= 5
            if ((inputLength >= 5) &&
                (-1 == (j = indexOfSet(localeStrsepsi + 1)))) {
                // no further separators, length must be 5
                if (inputLength != 5) {
                    throw new
                        IllegalArgumentException("Illegal locale String: " +
                                                 localeStr);
                }
                country = localeStr.substring(i + 1);
            }
            if (j != -1) {
                country = localeStr.substring(i + 1, j);
                // if we have enough separators for language, locale,
                // and variant, the length must be >= 8.
                if (inputLength >= 8) {
                    variant = localeStr.substring(j + 1);
                } else {
                    throw new
                        IllegalArgumentException("Illegal locale String: " +
                                                 localeStr);
                }
            }
        }
        if (variant != null && country != null && lang != null) {
            result = new Locale(langcountryvariant);
        } else if (lang != null && country != null) {
            result = new Locale(langcountry);
        } else if (lang != null) {
            result = new Locale(lang"");
        }
        return result;
    }


    

Parameters:
str local string
set the substring
fromIndex starting index
Returns:
starting at fromIndex, the index of the first occurrence of any substring from set in toSearch, or -1 if no such match is found
    private static int indexOfSet(String strchar[] setint fromIndex) {
        int result = -1;
        for (int i = fromIndexlen = str.length(); i < leni++) {
            for (int j = 0, innerLen = set.lengthj < innerLenj++) {
                if (str.charAt(i) == set[j]) {
                    result = i;
                    break;
                }
            }
            if (-1 != result) {
                break;
            }
        }
        return result;
    }

    

Set the Locale to be used in localizing the response being created for this view.

Parameters:
locale The new localization Locale
    public void setLocale(Locale locale) {
        getStateHelper().put(.locale);
        // Make sure to appraise the EL of this switch in Locale.
        FacesContext.getCurrentInstance().getELContext().setLocale(locale);
    }
    
    private Map<StringObjectviewScope = null;

    

This implementation simply calls through to getViewMap(boolean), passing true as the argument, and returns the result.

Since:
2.0
    public Map<StringObjectgetViewMap() {
        return getViewMap(true);
        
    }

    

Returns a Map that acts as the interface to the data store that is the "view scope", or, if this instance does not have such a Map and the create argument is true, creates one and returns it. This map must be instantiated lazily and cached for return from subsequent calls to this method on this UIViewRoot instance. javax.faces.application.Application.publishEvent(javax.faces.context.FacesContext,java.lang.Class,java.lang.Object) must be called, passing javax.faces.event.PostConstructViewMapEvent.class as the first argument and this UIViewRoot instance as the second argument.

The returned Map must be implemented such that calling clear() on the Map causes javax.faces.application.Application.publishEvent(javax.faces.context.FacesContext,java.lang.Class,java.lang.Object) to be called, passing javax.faces.event.PreDestroyViewMapEvent.class as the first argument and this UIViewRoot instance as the second argument.

Depending upon application configuration, objects stored in the view map may need to be Serializable. In general, it is a good idea to ensure that any objects stored in the view map are Serializable.

See javax.faces.context.FacesContext.setViewRoot(javax.faces.component.UIViewRoot) for the specification of when the clear() method must be called.

Parameters:
create true to create a new Map for this instance if necessary; false to return null if there's no current Map.
Since:
2.0
    public Map<StringObjectgetViewMap(boolean create) {
        if (create &&  == null) {
             = new ViewMap(getFacesContext().getApplication().getProjectStage());
            getFacesContext().getApplication()
                  .publishEvent(getFacesContext(),
                                PostConstructViewMapEvent.class,
                                this);
        }
        return ;
        
    }

Install the listener instance referenced by argument listener into the UIViewRoot as a listener for events of type systemEventClass.

Note that installed listeners are not maintained as part of the UIViewRoot's state.

Parameters:
systemEvent the Class of event for which listener must be fired.
listener the implementation of javax.faces.event.SystemEventListener whose javax.faces.event.SystemEventListener.processEvent(javax.faces.event.SystemEvent) method must be called when events of type systemEventClass are fired.
Throws:
NullPointerException if systemEventClass or listener are null.
Since:
2.0
    public void subscribeToViewEvent(Class<? extends SystemEventsystemEvent,
                                     SystemEventListener listener) {
        if (systemEvent == null) {
            throw new NullPointerException();
        }
        if (listener == null) {
            throw new NullPointerException();
        }
        
        if ( == null) {
             = new HashMap<Class<? extends SystemEvent>, List<SystemEventListener>>(4, 1.0f);
        }
        List<SystemEventListenerlisteners = .get(systemEvent);
        if (listeners == null) {
            listeners = new CopyOnWriteArrayList<SystemEventListener>();
            .put(systemEventlisteners);
        }
        listeners.add(listener);
    }


    

Remove the listener instance referenced by argument listener from the UIViewRoot as a listener for events of type systemEventClass.

Parameters:
systemEvent the Class of event for which listener must be fired.
listener the implementation of javax.faces.event.SystemEventListener whose javax.faces.event.SystemEventListener.processEvent(javax.faces.event.SystemEvent) method must be called when events of type systemEventClass are fired.
Throws:
NullPointerException if systemEventClass or listener are null.
Since:
2.0
    public void unsubscribeFromViewEvent(Class<? extends SystemEventsystemEvent,
                                         SystemEventListener listener) {
        if (systemEvent == null) {
            throw new NullPointerException();
        }
        if (listener == null) {
            throw new NullPointerException();
        }
        if ( != null) {
            List<SystemEventListenerlisteners = .get(systemEvent);
            if (listeners != null) {
                listeners.remove(listener);
            }
        }
    }


    

Return the SystemEventListener instances registered on this UIComponent instance that are interested in events of type eventClass.

Parameters:
systemEvent the Class of event for which the listeners must be returned.
Throws:
java.lang.NullPointerException if argument systemEvent is null.
Since:
2.0
    public List<SystemEventListenergetViewListenersForEventClass(Class<? extends SystemEventsystemEvent) {
        if (systemEvent == null) {
            throw new NullPointerException();
        }
        if ( != null) {
            return .get(systemEvent);
        }
        return null;
        
    }
    
    private void encodeViewParameters(FacesContext context) {
        ViewDeclarationLanguage vdl = context.getApplication().getViewHandler().
                    getViewDeclarationLanguage(contextgetViewId());
        if (vdl == null) {
            return;
        }
        ViewMetadata metadata = vdl.getViewMetadata(contextgetViewId());
        if (metadata != null) { // perhaps it's not supported
            Collection<UIViewParameterparams =
                  ViewMetadata.getViewParameters(this);
            if (params.isEmpty()) {
                return;
            }
            try {
                for (UIViewParameter param : params) {
                    param.encodeAll(context);
                }
            } catch (IOException e) {
                // IOException is forced by contract and is not expected to be thrown in this case
                throw new RuntimeException("Unexpected IOException"e);
            }
        }
    }
    // END TENATIVE
    // ----------------------------------------------------- StateHolder Methods
    private Object[] values;
    @Override
    public Object saveState(FacesContext context) {
        if (context == null) {
            throw new NullPointerException();
        }
        Object superState = super.saveState(context);
        Object attachedState = saveAttachedState(context);
        if (superState != null || attachedState != null) {
             = new Object[] {superStateattachedState};
        }
        return ();
    }
    @Override
    public void restoreState(FacesContext contextObject state) {
        if (context == null) {
            throw new NullPointerException();
        }
        if (state == null) {
            return;
        }
        
         = (Object[]) state;
        super.restoreState(context, values[0]);
        //noinspection unchecked
         = (Map<String,Object>) restoreAttachedState(context[1]);
        
    }
    // --------------------------------------------------------- Private Methods
    private static String getIdentifier(String target) {
        // check map