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.view;
 

Encapsulate the saving and restoring of the view to enable the VDL to take over the responsibility for handling this feature. Because ViewDeclarationLanguage.getStateManagementStrategy(javax.faces.context.FacesContext,java.lang.String) is required to return null for JSP views and non-null for views authored in Facelets for JSF 2, this specification only applys to Facelets for JSF 2.

Since:
2.0
 
 public abstract class StateManagementStrategy {

    
    

Return the state of the current view in an Object that implements Serializable. The default implementation must perform the following algorithm or its semantic equivalent.

  1. If the UIViewRoot of the current view is marked transient, return null immediately.

  2. Traverse the view and verify that each of the client ids are unique. Throw IllegalStateException if more than one client id are the same.

  3. Visit the tree using javax.faces.component.UIComponent.visitTree(javax.faces.component.visit.VisitContext,javax.faces.component.visit.VisitCallback). For each node, call javax.faces.component.StateHolder.saveState(javax.faces.context.FacesContext), saving the returned Object in a way such that it can be restored given only its client id. Special care must be taken to handle the case of components that were added or deleted programmatically during this lifecycle traversal, rather than by the VDL.

The implementation must ensure that the javax.faces.component.StateHolder.saveState(javax.faces.context.FacesContext) method is called for each node in the tree.

The data structure used to save the state obtained by executing the above algorithm must be Serializable, and all of the elements within the data structure must also be Serializable.

Parameters:
context the FacesContext for this request.
Since:
2.0
    public abstract Object saveView(FacesContext context);
    
    

Restore the state of the view with information in the request. The default implementation must perform the following algorithm or its semantic equivalent.

  1. Build the view from the markup. For all components in the view that do not have an explicitly assigned id in the markup, the values of those ids must be the same as on an initial request for this view. This view will not contain any components programmatically added during the previous lifecycle run, and it will contain components that were programmatically deleted on the previous lifecycle run. Both of these cases must be handled.

  2. Call javax.faces.render.ResponseStateManager.getState(javax.faces.context.FacesContext,java.lang.String) to obtain the data structure returned from the previous call to saveView(javax.faces.context.FacesContext).

  3. Visit the tree using javax.faces.component.UIComponent.visitTree(javax.faces.component.visit.VisitContext,javax.faces.component.visit.VisitCallback). For each node, call javax.faces.component.StateHolder.restoreState(javax.faces.context.FacesContext,java.lang.Object), passing the state saved corresponding to the current client id.

  4. Ensure that any programmatically deleted components are removed.

  5. Ensure any programmatically added components are added.

The implementation must ensure that the javax.faces.component.StateHolder.restoreState(javax.faces.context.FacesContext,java.lang.Object) method is called for each node in the tree, except for those that were programmatically deleted on the previous run through the lifecycle.

Parameters:
context the FacesContext for this request
viewId the view identifier for which the state should be restored
renderKitId the render kit id for this state.
Since:
2.0
    public abstract UIViewRoot restoreView(FacesContext contextString viewId,
                                           String renderKitId);
    
New to GrepCode? Check out our FAQ X