⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractviewbuildingstatemanager.java

📁 Please read your package and describe it at least 40 bytes in English. System will automatically de
💻 JAVA
字号:
/* * Copyright 2002-2004 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package de.mindmatters.faces.application;import java.io.IOException;import javax.faces.application.StateManager;import javax.faces.component.UIViewRoot;import javax.faces.context.FacesContext;import org.springframework.util.Assert;import de.mindmatters.faces.FacesUtils;/** * <strong>AbstractViewBuildingStateManager</strong> directs the process of * saving and restoring the view between requests. *  * <p> * This state manager <strong>only works with a view handler of type * {@link ViewBuilder}</strong>! Because an implemention of a ViewBuilder is * able to restore the structure of a component tree of a view without a given * serialized state this state manager writes no component structure state. This * class restores the component tree by invoking the method * {@link ViewBuilder#buildView(FacesContext, String)} of the configured view * handler. * </p> *  * <p> * Subclasses have to implement saving (see * {@link #getComponentStateToSave(FacesContext)}) and restoring (see * {@link #restoreComponentState(FacesContext, UIViewRoot, String)}) of the * component state. * </p> *  * @author Andreas Kuhrwahl * @see ViewBuilder#buildView(FacesContext, String) *  */public abstract class AbstractViewBuildingStateManager extends StateManager {    /** The original state manager of the underlying JSF implementation. */    private final StateManager delegate;    /**     * Creates an StateManager with the given state manager     * <code>delegate</code> of the underlying JSF implementation.     *      * @param delegate     *            the original state manager of the underlying JSF     *            implementation     */    public AbstractViewBuildingStateManager(final StateManager delegate) {        super();        this.delegate = delegate;    }    /**     * Throws an IllegalStateException if the configured view handler is not of     * type ViewBuilder.     *      * @param context     *            {@link FacesContext} for the current request     * @throws IllegalStateException     *             if the configured ViewHandler is not of type ViewBuilder     */    private void checkViewHandler(final FacesContext context) {        if (!(context.getApplication().getViewHandler() instanceof ViewBuilder)) {            throw new IllegalStateException(                    "Optimized state-saving is not supported with the applied ViewHandler. "                            + "Use a ViewBuilder instance instead.");        }    }    /**     * {@inheritDoc}     */    public final SerializedView saveSerializedView(final FacesContext context) {        checkViewHandler(context);        SerializedView result = null;        UIViewRoot viewRoot = context.getViewRoot();        if (!viewRoot.isTransient()) {            if (isSavingStateInClient(context)) {                result = new SerializedView(getTreeStructureToSave(context),                        getComponentStateToSave(context));            } else {                result = this.delegate.saveSerializedView(context);            }        }        return result;    }    /**     * {@inheritDoc}     */    protected final Object getTreeStructureToSave(final FacesContext context) {        return null;    }    /**     * {@inheritDoc}     */    public void writeState(final FacesContext context,            final SerializedView state) throws IOException {        checkViewHandler(context);        this.delegate.writeState(context, state);    }    /**     * {@inheritDoc}     */    public final UIViewRoot restoreView(final FacesContext context,            final String viewId, final String renderKitId) {        checkViewHandler(context);        UIViewRoot viewRoot = null;        if (isSavingStateInClient(context)) {            Assert.notNull(renderKitId);            viewRoot = restoreTreeStructure(context, viewId, renderKitId);            if (viewRoot != null) {                restoreComponentState(context, viewRoot, renderKitId);            }        } else {            this.delegate.restoreView(context, viewId, renderKitId);        }        return viewRoot;    }    /**     * {@inheritDoc}     */    protected final UIViewRoot restoreTreeStructure(final FacesContext context,            final String viewId, final String renderKitId) {        UIViewRoot viewRoot = null;        if (FacesUtils.isPostback(context)                && !context.getExternalContext().getRequestParameterMap()                        .containsKey(FacesUtils.TRANSIENT_PARAM)) {            ViewBuilder viewBuilder = (ViewBuilder) context.getApplication()                    .getViewHandler();            viewRoot = viewBuilder.buildView(context, viewId);        }        return viewRoot;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -