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

📄 restoreviewphase.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.spring.context.servlet.lifecycle;import javax.faces.application.ViewHandler;import javax.faces.component.ActionSource;import javax.faces.component.UICommand;import javax.faces.component.UIViewRoot;import javax.faces.context.FacesContext;import javax.faces.el.MethodBinding;import javax.faces.event.ActionEvent;import javax.faces.event.ActionListener;import de.mindmatters.faces.spring.context.servlet.LifecycleExecutor;/** * <em>Restore View</em> Phase implementation used by the special JSF-Spring * {@link javax.faces.lifecycle.Lifecycle} identified by * {@link de.mindmatters.faces.lifecycle.LifecycleImpl#JSF_SPRING_LIFECYCLE_ID}. *  * <p> * Checks whether the currently executing Spring MVC Handler implements * {@link RestoreViewPhaseListener} or defines a method<br/> * <code>public void beforeRestoreView(FacesContext context)</code> <br/>or * <br/><code>public void afterRestoreView(FacesContext context)</code> * <br/>respectively and invokes the appropriate one at the beginning and the * end of phase processing. * </p> *  * @author Andreas Kuhrwahl *  */public class RestoreViewPhase extends        de.mindmatters.faces.lifecycle.RestoreViewPhase {    /**     * UICommand that delegates its {@link ActionSource} methods to the given     * ActionSource.     *      * @author Andreas Kuhrwahl     *      */    private class DelegatingActionSource extends UICommand {        /** The internal {@link ActionSource} delegate. */        private final ActionSource actionSource;        /**         * Creates the {@link UICommand}.         *          * @param actionSource         *            the delegate         */        public DelegatingActionSource(final ActionSource actionSource) {            this.actionSource = actionSource;            initActionListeners();        }        /**         * Registers the {@link ActionListener}s of th given ActionSource.         */        private void initActionListeners() {            ActionListener[] actionListeners = this.actionSource                    .getActionListeners();            for (int i = 0; i < actionListeners.length; i++) {                super.addActionListener(actionListeners[i]);            }        }        /**         * {@inheritDoc}         */        public void addActionListener(final ActionListener listener) {            super.addActionListener(listener);            actionSource.addActionListener(listener);        }        /**         * {@inheritDoc}         */        public MethodBinding getAction() {            return actionSource.getAction();        }        /**         * {@inheritDoc}         */        public MethodBinding getActionListener() {            return actionSource.getActionListener();        }        /**         * {@inheritDoc}         */        public boolean isImmediate() {            return actionSource.isImmediate();        }        /**         * {@inheritDoc}         */        public void removeActionListener(final ActionListener listener) {            super.removeActionListener(listener);            actionSource.removeActionListener(listener);        }        /**         * {@inheritDoc}         */        public void setAction(final MethodBinding action) {            actionSource.setAction(action);        }        /**         * {@inheritDoc}         */        public void setActionListener(final MethodBinding actionListener) {            actionSource.setActionListener(actionListener);        }        /**         * {@inheritDoc}         */        public void setImmediate(final boolean immediate) {            actionSource.setImmediate(immediate);        }    }    /**     * {@inheritDoc}     */    protected final UIViewRoot createView(final FacesContext context,            final ViewHandler viewHandler, final String viewId) {        UIViewRoot viewRoot = viewHandler.createView(context, viewId);        appendActionSource(context, viewRoot, LifecycleExecutor                .getHandler(context));        return viewRoot;    }    /**     * Appends an {@link ActionSource} to the given {@link UIViewRoot}     * <code>viewRoot</code> and queues an {@link ActionEvent} to the newly     * attached ActionSource. Necessary because the <em>Invoke Application</em>     * phase has to be executed.     *      * @param context     *            {@link FacesContext} for the current request     * @param viewRoot     *            the created {@link UIViewRoot}     * @param handler     *            the current handler     */    protected void appendActionSource(final FacesContext context,            final UIViewRoot viewRoot, final Object handler) {        UICommand command = null;        if (handler instanceof ActionSource) {            command = new DelegatingActionSource((ActionSource) handler);        } else {            command = new UICommand();        }        command.setRendererType(null);        viewRoot.getChildren().add(command);        command.queueEvent(new ActionEvent(command));    }    /**     * {@inheritDoc}     */    protected void afterPhase(final FacesContext context) {        PhaseListenerHelper.getInstance().afterPhase(context,                LifecycleExecutor.getHandler(context),                RestoreViewPhaseListener.class);    }    /**     * {@inheritDoc}     */    protected void beforePhase(final FacesContext context) {        PhaseListenerHelper.getInstance().beforePhase(context,                LifecycleExecutor.getHandler(context),                RestoreViewPhaseListener.class);    }}

⌨️ 快捷键说明

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