com.sun.faces.application.view.StateManagementStrategyImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javax.faces Show documentation
Show all versions of javax.faces Show documentation
This is the master POM file for Oracle's Implementation of the JSF 2.2 Specification.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2011 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 com.sun.faces.application.view;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.FactoryFinder;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.component.visit.VisitResult;
import javax.faces.context.FacesContext;
import javax.faces.render.ResponseStateManager;
import com.sun.faces.component.visit.VisitUtils;
import com.sun.faces.context.StateContext;
import com.sun.faces.renderkit.RenderKitUtils;
import com.sun.faces.util.ComponentStruct;
import com.sun.faces.util.FacesLogger;
import com.sun.faces.util.MessageUtils;
import com.sun.faces.util.Util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.io.IOException;
import javax.faces.application.StateManager;
import javax.faces.component.ContextCallback;
import javax.faces.component.visit.VisitCallback;
import javax.faces.component.visit.VisitContext;
import javax.faces.view.StateManagementStrategy;
import javax.faces.FacesException;
import javax.faces.application.Application;
import javax.faces.event.PostRestoreStateEvent;
import javax.faces.view.ViewDeclarationLanguage;
import javax.faces.view.ViewDeclarationLanguageFactory;
/**
*
* A StateManager
implementation to meet the requirements
* of the specification.
*
*
*
* For those who had compile dependencies on this class, we're sorry for any
* inconvenience, but this had to be re-worked as the version you depended on
* was incorrectly implemented.
*
*/
public class StateManagementStrategyImpl extends StateManagementStrategy {
private static final Logger LOGGER = FacesLogger.APPLICATION_VIEW.getLogger();
private final ViewDeclarationLanguageFactory vdlFactory;
private static final String CLIENTIDS_TO_REMOVE_NAME =
"com.sun.faces.application.view.CLIENTIDS_TO_REMOVE";
private static final String CLIENTIDS_TO_ADD_NAME =
"com.sun.faces.application.view.CLIENTIDS_TO_ADD";
// ------------------------------------------------------------ Constructors
/**
* Create a new StateManagerImpl
instance.
*/
public StateManagementStrategyImpl() {
vdlFactory = (ViewDeclarationLanguageFactory)
FactoryFinder.getFactory(FactoryFinder.VIEW_DECLARATION_LANGUAGE_FACTORY);
}
// ----------------------------------------------- Methods from StateManager
/**
* @see {@link javax.faces.application.StateManager#saveView(javax.faces.context.FacesContext))
*/
@Override
public Object saveView(FacesContext context) {
if (context == null) {
return null;
}
// irrespective of method to save the tree, if the root is transient
// no state information needs to be persisted.
UIViewRoot viewRoot = context.getViewRoot();
if (viewRoot.isTransient()) {
return null;
}
// honor the requirement to check for id uniqueness
Util.checkIdUniqueness(context,
viewRoot,
new HashSet(viewRoot.getChildCount() << 1));
final Map stateMap = new HashMap();
// -----------------------------------------------------------------------------
// COMMENTED OUT DUE TO ISSUE 1310 UNTIL NEW VISIT HINTS CAN BE
// ADDED TO THE API
// -----------------------------------------------------------------------------
// VisitContext visitContext = VisitContext.createVisitContext(context);
// final FacesContext finalContext = context;
// viewRoot.visitTree(visitContext, new VisitCallback() {
//
// public VisitResult visit(VisitContext context, UIComponent target) {
// VisitResult result = VisitResult.ACCEPT;
// Object stateObj;
// if (!target.isTransient()) {
// if (target.getAttributes().containsKey(DYNAMIC_COMPONENT)) {
// stateObj = new StateHolderSaver(finalContext, target);
// } else {
// stateObj = target.saveState(context.getFacesContext());
// }
// if (null != stateObj) {
// stateMap.put(target.getClientId(context.getFacesContext()),
// stateObj);
// }
// } else {
// return result;
// }
//
// return result;
// }
//
// });
// -----------------------------------------------------------------------------
StateContext stateContext = StateContext.getStateContext(context);
// PENDING: Use of VisitUtils and FacesContext Attribute For Visit Hints
// until new Visit Hints defined in spec.
// See: https://javaserverfaces-spec-public.dev.java.net/issues/show_bug.cgi?id=545
VisitUtils.startStateSaveRestore(context);
// ADDED FOR ISSUE 1310 - REMOVE ONCE NEW VISIT HINTS ARE ADDED TO THE
// API
saveComponentState(viewRoot, context, stateContext, stateMap);
// PENDING: Use of VisitUtils and FacesContext Attribute For Visit Hints
// until new Visit Hints defined in spec.
// See: https://javaserverfaces-spec-public.dev.java.net/issues/show_bug.cgi?id=545
VisitUtils.endStateSaveRestore(context);
// handle dynamic adds/removes
List removeList = stateContext.getDynamicRemoves();
if (null != removeList && !removeList.isEmpty()) {
stateMap.put(CLIENTIDS_TO_REMOVE_NAME, removeList);
}
Map addList = stateContext.getDynamicAdds();
if (null != addList && !addList.isEmpty()) {
List